score:1

Accepted answer

your output expression is keeping a reference to the old x symbol, but instead it should be a reference to a new one. therefore, you can reset all the junk references in the tree you aim to reuse by applying resetlocalattrs from context.

how about...?

def mimpl(c: context)(bodyblock: c.expr[unit]): c.expr[x] =
  c.universe.reify {
    new x(new specialfunction {
      override def apply() {
        c.expr[unit](c.resetlocalattrs(bodyblock.tree)).splice
      }
    })
  }

in this question, you can read a great explanation by the scala macros guy.


Related Query

More Query from same tag