Scala quasiquote generating parameter default value with backticks

234 Views Asked by At

I need to generate:

case class Foo(param: Bar = BarEnum.SomeCaseObject)

But this code:

val term = TermName("BarEnum.SomeCaseObject") 
showCode(q"""case class Foo(val param : Bar = ${term})""") 

outputs the parameter default surrounded by backticks, which doesn't compile:

case class Foo(param: Bar = `BarEnum.SomeCaseObject`)

How can I get the default parameter value output without the backticks?

1

There are 1 best solutions below

0
On BEST ANSWER

You are trying to create value with name "BarEnum.SomeCaseObject", that's illegal identifier, thus in backticks.

You can use Select(Ident(TermName("BarEnum")), TermName("SomeCaseObject")) or (better) q"BarEnum.SomeCaseObject" (assuming that SomeCaseObject is a term).