Open
Description
Example:
import scala.reflect.runtime.universe._
class Test[T: TypeTag] {
type X = List[T]
val tpe = typeOf[X].dealias
}
object Main extends App {
val t1 = new Test[Int].tpe
val t2 = typeOf[List[Int]]
println(t1)
// List[T]
println(t2)
// List[Int]
assert(t1 =:= t2)
// java.lang.AssertionError: assertion failed
}
This behavior is inconsistent with current behavior of type
declarations in defs – they fail as expected:
def test[T: TypeTag] = {
type X = List[T]
typeOf[X]
}
// Error:(22, 10) No TypeTag available for X
// typeOf[X]
// ^
I think, intuitively, the code above should fail to compile – TypeTag
s should never contain uninstantiated type variables. User shouldn't be able to summon a type tag inside the class body, when variables haven't been instantiated yet, only outside with a type projection: typeOf[Test[String]#X]
scala 2.12.6