0
這條線:Scala中未找到:值宏
"foo".assertNonFatal(_ equals "foo", "error message");
此錯誤:
Error:(120, 47) not found: value assertion
該鉤子:
final implicit class ImplicitAssert[MyType](val me: MyType) {
final def assertNonFatal(assertion: (MyType) => Boolean, message: String)
: MyType = macro ImplicitAssertMacros.assertNonFatal[MyType]
}
該宏:
object ImplicitAssertMacros {
def assertNonFatal[MyType](c: scala.reflect.macros.blackbox.Context)
(assertion: c.Tree, message: c.Tree): c.Tree = {
import c.universe._
val me = q"${c.prefix}.me" // "me" from ImplicitAssert class.
val numLines = q"Int.MaxValue"
val useStdOut = q"false"
val assertionTrue = q"assertion($me)"
val isFatal = q"false"
val toReturn = q"""
_root_.info.collaboration_station.debug.internal.Printer.traceInternalAssert($message, $numLines, $useStdOut, $assertionTrue, $isFatal);
$me;
"""
toReturn
}
}
^我不知道這個編譯器錯誤的原因是什麼或如何解決它。
請注意,它只發生在我編譯源文件而不是宏時。
在編譯調用宏的代碼之前,在編譯會話之前編譯宏嗎? – pedrofurla
@pedrofurla - 在sbt的宏中運行「compile」以[success]結束。爲「foo」運行「test:compile」.assertNonFatal(_ equals「foo」,「error message」)以「not found:value assertion」結尾 –