I don't know why this worked before and not anymore in 2.13.0-M3, but Trees$Literal
is sort of an implementation detail. It's how names of inner classes are encoded by the compiler. An actual Scala type with which you can refer to that class is the type projection Trees#Literal
.
So what will probably work is
const.asInstanceOf[scala.reflect.internal.Trees#Literal].value.value
I'm guessing value()
in your code used to work because the compiler didn't recognize Trees$Literal
as a Scala type anymore, and in Java all methods have a parameter list. A Scala def foo
compiles to a method with a parameter list, but the compiler can see in the Scala-specific metadata if it's a method without parameter list or not. A (non local) val
compiles to a field and a method.
By the way, interesting as this may be, I don't think you actually need to cast to the internal API for this. You can simply pattern match to get the value out of the literal constant. With Literal
and Constant
imported from scala.reflect.runtime.universe
or c.universe
(c
being a macro context):
val Literal(Constant(value: String)) = const
or
const match {
case Literal(Constant(value: String)) => value
}
scala.reflect.internal.Trees#Literal
say?scala.reflect.internal.Trees#Literal
?Trees$Literal
is sort of an implementation detail.value
is probably aval
or adef
without parameter list