I'm working on a project (
https://github.com/pniederw/expecty) that
uses a macro to bring Groovy/Spock-style power assertions to Scala.
(I'm the original author of Groovy power asserts.) Currently, the
project is based on the Scala Macros ("Kepler") fork.
Initially, I tried to use Context.reify() as much as possible. After
all, who wants to construct ASTs by hand? I started out with something
like this:
val expr: c.Tree = ...
c.reify {
val runtime = new org.expectify.Runtime
runtime.record(expr.eval)
}
This worked fine. Next I needed to do the same for a variable number
of expressions. I tried something like:
val exprs: List[c.Tree] = ...
c.reify {
val runtime = new org.expectify.Runtime
for (expr <- exprs) runtime.record(expr.value)
}
Obviously this doesn't work because the loop needs to get executed at
macro expansion time. So I tried to use multiple reify's (one for the
val and another one for each expression) and manually combined the
resulting expressions into a Block. This resulted in a new problem,
namely that the compiler wasn't able to resolve the references to the
val anymore. In the end, the only way I was able to make this work was
to give up on reify and construct all ASTs by hand. Is there a better
way?
Cheers,
Peter
PS: Is this the right list for this kind of macro-related questions?