This is a simplified version of the problem I am facing but the underlying issue remains. After calling a macro, I want to generate case classes dynamically. I am able to retrieve parameters from macro call etc. The issue I am having is trying to use a string variable within quasiquotes. I essentially want to have the following:
def expand_impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
val toGen = "case class Foo()"
val toReturn = c.Expr[Any](
q"$toGen"
)
toReturn
}
However, the case class is not generated. Now I know that if I change toGen to q"case class Foo()" it will work, however toGen is a string I will generate after some other processing which returns a string, so I can't do that. Compiling it like this and manually looking at the the value of toReturn I get the following:
Expr[Any]("case class Foo()")
The string toGen is simply pasted in, along the quotes, meaning the case class is not generated.
I have looked for similar issues but can't find this example anywhere. How can I unquote the double quotes of a string variable within quasiquotes?
val toGen = someMethod(). The string that is returned bysomeMethod()will be something like "case class Foo()". If understand you correctly you are suggesting I should use quasiquotes when returning the case class? However this is where my problem lies, becausesomeMethod(), will not always return the same case class, it dynamically generates them based on the input etc. and returns a string.