我正在尝试将我的代码库从 2.11.8 升级到 2.13.15 我的 HandOnSuite 特征中有一个错误
trait HandsOnSuite extends AnyFunSpec with Matchers with ScalaFutures {
def exercice(testName: String)(testFun: Unit)(implicit suite: HandsOnSuite): Unit = macro ExerciceMacro.apply
}
找不到宏定义的
apply
方法
package support
import scala.reflect.macros.blackbox
import scala.reflect.macros.blackbox.Context
class ExerciceMacro[C <: Context](val c: C) {
import c.universe._
def apply(testName: c.Expr[String])(testFun: c.Expr[Unit])(suite: c.Expr[HandsOnSuite]): c.Expr[Unit] = {
val code = testFun.tree.pos.source.content.mkString
val (start, end) = testFun.tree match {
case Block(xs, expr) => (testFun.tree.pos.line, expr.pos.line)
case _ => (testFun.tree.pos.line, testFun.tree.pos.line)
}
c.Expr(q"""$suite.testExercice($testName)($testFun)(new support.TestContext($code, $start, $end))""")
}
}
object ExerciceMacro {
def apply(c: blackbox.Context)(testName: c.Expr[String])(testFun: c.Expr[Unit])(suite: c.Expr[HandsOnSuite]): c.Expr[Unit] = {
new ExerciceMacro[c.type](c).apply(testName)(testFun)(suite)
}
}
有什么关于如何升级的提示吗? 我找不到一些有关宏的文档
使用 Intellij,我使缓存失效,但它不起作用
尝试更换这个
class ExerciceMacro[C <: Context](val c: C) {
import c.universe._
def apply(testName: c.Expr[String])(testFun: c.Expr[Unit])(suite: c.Expr[HandsOnSuite]): c.Expr[Unit] = ...
}
object ExerciceMacro {
def apply(c: blackbox.Context)(testName: c.Expr[String])(testFun: c.Expr[Unit])(suite: c.Expr[HandsOnSuite]): c.Expr[Unit] = ...
}
这样:
class ExerciceMacro(val c: blackbox.Context) {
import c.universe._
def apply(testName: c.Expr[String])(testFun: c.Expr[Unit])(suite: c.Expr[HandsOnSuite]): c.Expr[Unit] = ...
}
// no companion object