Skip to content

Instantly share code, notes, and snippets.

@Jasper-M
Created February 16, 2017 16:39
Show Gist options
  • Save Jasper-M/12171b0c191cd7afde5e71bbb1c86d39 to your computer and use it in GitHub Desktop.
Save Jasper-M/12171b0c191cd7afde5e71bbb1c86d39 to your computer and use it in GitHub Desktop.
scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._
scala> class Bar { type T; def bar = weakTypeTag[T] }
defined class Bar
scala> object Barr extends Bar { type T = Int }
defined object Barr
scala> val tag = Barr.bar
tag: reflect.runtime.universe.WeakTypeTag[Barr.T] = WeakTypeTag[Bar.this.T]
scala> tag.tpe.typeSymbol.asType.isAbstractType
<console>:16: warning: method isAbstractType in trait TypeSymbolApi is deprecated (since 2.11.0): use isAbstract instead
tag.tpe.typeSymbol.asType.isAbstractType
^
res0: Boolean = true
scala> tag.tpe.typeSymbol.asType.isAbstract
res1: Boolean = true
scala> tag.tpe.typeSymbol.asType.isInstanceOf[FreeTypeSymbolApi]
res2: Boolean = true
scala> class Baz { type T; def baz(implicit tag: WeakTypeTag[T]) = weakTypeTag[T] }
defined class Baz
scala> object Bazz extends Baz { type T = Int }
defined object Bazz
scala> val tag = Bazz.baz
tag: reflect.runtime.universe.WeakTypeTag[Bazz.T] = TypeTag[Bazz.T]
scala> tag.tpe.typeSymbol.asType.isAbstractType
<console>:16: warning: method isAbstractType in trait TypeSymbolApi is deprecated (since 2.11.0): use isAbstract instead
tag.tpe.typeSymbol.asType.isAbstractType
^
res3: Boolean = false
scala> tag.tpe.typeSymbol.asType.isAbstract
res4: Boolean = true
scala> tag.tpe.typeSymbol.asType.isInstanceOf[FreeTypeSymbolApi]
res5: Boolean = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment