:これは次のエラーで失敗しと抽象メソッドを実装defのマクロ
import scala.reflect.macros.Context
import language.experimental.macros
trait A {
def foo(): Unit
}
object AImpl {
def fooImpl(c: Context)(): c.Expr[Unit] = {
import c.universe._
c.Expr[Unit](reify().tree)
}
}
trait AImpl extends A {
def foo(): Unit = macro AImpl.fooImpl
}
:
[error] .../A.scala:17: overriding method foo in trait A of type()Unit;
[error] macro method foo cannot override an abstract method
[error] def foo(): Unit = macro AImpl.fooImpl
[error] ^
私はにそれを削除した場合コンパイルする。しかし明らかに、私はAImpl
が形質A
を満たすことを望んでいます。これを修正するには?
もう一つの試み:
trait AImpl extends A {
def foo(): Unit = bar()
def bar(): Unit = macro AImpl.fooImpl
}
は、新しいエラーを与える:
[error] macro implementation not found: bar (the most common reason for that is that
you cannot use macro implementations in the same compilation run that defines them)
[error] one error found
実際に '(a:AImpl).foo()'をマクロとして使用サイトで展開する必要があるか、 (通常の) 'foo()'メソッド? – gourlaysama