I'm writing macro to convert a type description into a singleton type:
object Type2String {
def apply[I]: Witness.Lt[String] = macro Macros.apply[I]
final class Macros(val c: whitebox.Context) extends MWithReflection {
import c.universe._
def apply[A: WeakTypeTag]: Tree = {
val tt: Type = weakTypeOf[A]
val str = tt.toString
// val vv = viz(tt)
q"shapeless.Witness.mkWitness[$str]($str)"
}
}
}
The problem is that since A only has a WeakTypeTag. It cannot extract the correct info from generic types:
case class ^^[T1, T2]() {
final val wTSelf = Type2String[^^[T1, T2]]
}
val e1 = ^^[Int, String]()
e1.wTSelf
This gives the wrong Witness type: shapeless.Witness.Aux[String("T1 ^^ T2")]
So my questions are:
It is compile-time, the type information should be fully visible, why are T1 and T2 erased?
How to fix this program so it gives the correct type info:
shapeless.Witness.Aux[String("Int ^^ String")]
?