Desugaring TypeTag's in Scala

Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Desugaring TypeTag's in Scala

Joe San

I have the following code snippet:

import scala.reflect.runtime.universe._

def paramInfo[N: TypeTag](x: N): Unit = {
  val targs = typeOf[N] match { case TypeRef(_, _, args) => args }
  println(s"type of $x has type arguments $targs")

case class Dummy(l: List[Int])

import scala.reflect.runtime.universe._
paramInfo: [N](x: N)(implicit evidence$1: reflect.runtime.universe.TypeTag[N])Unit
defined class Dummy

// Exiting paste mode, now interpreting.

type of Dummy(List(1, 2)) has type arguments List()

scala> paramInfo(List(1,2))
type of List(1, 2) has type arguments List(Int)

scala> paramInfo(Dummy(List(1,2)))
type of Dummy(List(1, 2)) has type arguments List()

What I do not understand is that I was expecting the call paramInfo(Dummy(List(1,2))) to actually print:

type of Dummy(List(1, 2)) has type arguments List(Dummy(List(Int)))

Did I get it wrong? Any reason?

You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit