Scala Macros: Generated class fails to compile with unimplemented members -
my problem generated class' members not getting recognised implemented. being built scala 2.10/2.11/2.12 2.11 being default. using macroparadise 2.10.
goal of mark traits freezable , generate implementation class each takes scala.util.try
each method freezable have get
method called when accessing data. unfreezable methods filled in throw new illegalstateexception
. , custom freeze
method created creates instance of frozen
class filled in data needed using methods defined trait.
i have set annotation macro placed on traits , generate companion object inner class called frozen
below:
{ abstract trait javainfo extends scala.anyref { @new canfreeze() def isjavainfo: boolean; @new cannotfreeze() def tojavainfo: anyref }; object javainfo extends scala.anyref { def <init>() = { super.<init>(); () }; class frozen extends javainfo java.io.serializable { <paramaccessor> private val $isjavainfo: scala.util.try[boolean] = _; def <init>($isjavainfo: scala.util.try[boolean]) = { super.<init>(); () }; override def isjavainfo: boolean = this.$isjavainfo.get; override def tojavainfo: anyref = throw new illegalstateexception("method not frozen!") }; def freeze(valuetofreeze: javainfo): frozen = new frozen(scala.util.try.apply(valuetofreeze.isjavainfo)) }; () }
the following error occurs when try run macro on trait javainfo
:
[error] /users/senk/projects/scala-debugger/scala-debugger-api/src/main/scala/org/scaladebugger/api/profiles/traits/info/javainfo.scala:9: class frozen needs abstract, since: [error] has 2 unimplemented members. [error] /** seen class frozen, missing signatures follows. [error] * convenience, these usable stub implementations. [error] */ [error] override def isjavainfo: boolean = ??? [error] override def tojavainfo: anyref = ??? [error] @freezable trait javainfo { [error] ^ [error] 1 error found
the trait follows:
import org.scaladebugger.macros.freeze.{canfreeze, cannotfreeze, freezable} @freezable trait javainfo { @canfreeze def isjavainfo: boolean @cannotfreeze def tojavainfo: anyref }
get error nothing has been implemented frozen
class, though see implementation in tree i'm building.
code in question here: https://github.com/chipsenkbeil/scala-debugger/blob/addfreezablemacrosupport/scala-debugger-macros/src/main/scala/org/scaladebugger/macros/freeze/freezablemacro.scala
you can test failure checking out branch , running sbt scaladebuggerapi/compile
, compile macros project scala 2.11 followed api itself.
figured out. creating methods , implementing bodies, reusing old modifiers of each method , tacking on flag.override: flagset
. turns out unimplemented methods have flag.deferred
on them, producing modifiers(override | deferred)
, didn't make sense considering had body. seems having modifier of deferred
cause compiler ignore body when checking method, though body show in byte code itself.
Comments
Post a Comment