Here is a simple example in shapeless:
it("from Witness") {
val ttg = implicitly[TypeTag[Witness.Lt[String]]]
val ctg = implicitly[ClassTag[Witness.Lt[String]]]
}
it("... from macro") {
val ttg = implicitly[TypeTag[Witness.`1`.T]]
val ctg = implicitly[ClassTag[Witness.`1`.T]]
}
it("... doesn't work") {
val ttg = implicitly[TypeTag[w1.T]] // failed!
val ctg = implicitly[ClassTag[w2.T]]
}
The second and third it
block have very similar bytecode (after the Witness.?
macro has been invoked), yet one succeed and one failed:
[Error] /home/peng/git-spike/scalaspike/common/src/test/scala/com/tribbloids/spike/scala_spike/Reflection/InferTypeTag.scala:55: No TypeTag available for com.tribbloids.spike.scala_spike.Reflection.InferTypeTag.w1.T
What could have caused this? And how do I circumvent this problem?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…