Skip to content

Generates invalid TypeTag with free type variables in member types if member types reference type parameters #11139

Open
@neko-kai

Description

@neko-kai

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 – TypeTags 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions