I wanted to write a macro that will inspect and modify a lamba. For now macro looks like this (it doesn't do any modification):
object Macro {
def literalInt(c: blackbox.Context)(func: c.Expr[Int => Int]): c.Expr[Int => Int] = {
import c.universe._
val Function(params, body) = func.tree
c.Expr(Function(params, body))
}
def lit(func: Int => Int): Int => Int = macro literalInt
}
It works fine for trivial lambdas, like:
Macro.lit(_ + 19)
but it fails on
Macro.lit { args =>
val temp = 10
args + temp * 2
}
with error:
scalac: Error while emitting App.scala
value temp
Does anyone know what and why is going on?