I have a ClassSymbol
and want to generate a zero-argument method throwing ???
. Here are my attempts:
Assume that object Test
is the type we have ClassSymbol
of.
I.
val sym = //the ClassSymbol
val tpe = tq"$sym.type"
q"def foo(): $tpe = ???"
Result:
[error] stable identifier required, but Test.type found.
II.
val sym = //the ClassSymbol
val tpe = tq"${sym.name}.type"
q"def foo(): $tpe = ???"
Result:
[error] found : c.universe.TypeName
[error] required: c.universe.TermName
[error] val tpe = tq"${sym.name}.type"
III.
val sym = //the ClassSymbol
val tpe = tq"${TermName(sym.name.toString)}.type"
q"def foo(): $tpe = ???"
Result:
Compiles successfully
So I ended up using the method III which looks pretty scary.
Is there a "native" way to use ClassSymbol
in a quasiquote?