より大きな例から抽出された次のマクロは、への参照だけでツリーを作成することになっていますthis
。
def echoThisImpl(c:Context): c.Expr[Any] = {
import c.universe._
val selfTree = This(c.enclosingClass.symbol)
c.Expr[AnyRef](selfTree)
}
def echoThis: Any = macro CallMacro.echoThisImpl
しかし、次のようechoThis
な呼び出し
object Testing extends App {
val thisValue = CallMacro.echoThis
println(thisValue)
}
コンパイルに失敗し、メッセージが表示されます
[error] /home/rafael/dev/scala/goose/goose-macros/src/test/scala/Testing.scala:8: type mismatch;
[error] found : <noprefix>
[error] required: Any
[error] val thisValue = CallMacro.echoThis
-Ymacro-debug-liteフラグを設定すると、生成されるツリーはThis(newTermName("<local Testing>"))
.