出于某种原因,每当我尝试使用quasiquotes中的隐式参数调用函数时,它都会失败
Can't unquote x.universe.Tree, consider providing an implicit instance of Liftable[x.universe.Tree]
这有什么问题?我不被允许这样做吗?我无法找到它说不能做的任何地方
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
object Foo {
def foo: Unit = macro fooImpl
def fooImpl(c: whitebox.Context): c.Expr[Unit] = {
import c.universe._
implicit val x = c
val res = q"$sysoutFQN"
c.Expr(res)
}
def sysoutFQN(implicit c: whitebox.Context): c.universe.Tree = {
import c.universe._
q"java.lang.System.out.println()"
}
}
答案 0 :(得分:1)
因为路径依赖于c.universe.Tree != x.universe.Tree
所以你需要写x type
implicit val x: c.type = c