On Fri, Apr 20, 2012 at 12:08 PM, Eugene Burmako <eugene....@epfl.ch> wrote: > Bottom line. Macro expansions cannot refer to the values defined in a macro > unless you splice.
An additional note: The important thing you have to always remember when dealing with macros is that you are really mainly operating on expression trees, not on runtime values. So, if you splice (using `.eval` inside of `reify`) you have to splice in trees not values.
Incidentally: I think the surprising thing here is that evaluating expression trees (using `.eval` outside of `reify`) at macro expansion time works for some expressions. Eugene, is there some effort to improve error messages in cases this fails? For example, calling the example macro from this thread with `MacroRegex.build("abc"*3)` results in a
[error] /home/johannes/git/self/scala-days/src/test/scala/MacroTest.scala:2: exception during macro expansion: [error] scala.tools.nsc.ToolBoxes$ToolBox$ToolBoxError: reflective toolbox has failed: cannot operate on trees that are already typed [error] at scala.tools.nsc.ToolBoxes$ToolBox.runExpr(ToolBoxes.scala:50) [error] at scala.reflect.api.Exprs$Expr.eval(Exprs.scala:15)
at compilation of user code which may be confusing. Probably it's the responsibility of the macro to catch those problems, are there any helpers to do that effectively?