Created
October 30, 2014 06:41
-
-
Save xuwei-k/0348d85d3b80fcce1094 to your computer and use it in GitHub Desktop.
AbstractMethodError when override using macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_67). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
import scala.language.experimental.macros | |
import scala.reflect.macros.Context | |
trait A{ | |
def x: Int = 1 | |
} | |
object B { | |
def impl(c: Context): c.Expr[Int] = { | |
import c.universe._ | |
c.Expr[Int](Literal(Constant(2))) | |
} | |
} | |
class B extends A { | |
override def x: Int = macro B.impl | |
} | |
// Exiting paste mode, now interpreting. | |
import scala.language.experimental.macros | |
import scala.reflect.macros.Context | |
defined trait A | |
defined module B | |
defined class B | |
scala> val b = new B | |
b: B = B@47825164 | |
scala> b.x | |
res0: Int = 2 | |
scala> (b: A).x | |
java.lang.AbstractMethodError: B.x()I | |
at .<init>(<console>:14) | |
at .<clinit>(<console>) | |
at .<init>(<console>:7) | |
at .<clinit>(<console>) | |
at $print(<console>) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:606) | |
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734) | |
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983) | |
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573) | |
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604) | |
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568) | |
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:760) | |
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:805) | |
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:717) | |
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:581) | |
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:588) | |
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:591) | |
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:882) | |
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837) | |
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:837) | |
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) | |
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:837) | |
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83) | |
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96) | |
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105) | |
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_67). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
import scala.language.experimental.macros | |
import scala.reflect.macros.Context | |
trait A{ | |
def x: Int = 1 | |
} | |
object B { | |
def impl(c: Context): c.Expr[Int] = { | |
import c.universe._ | |
c.Expr[Int](Literal(Constant(2))) | |
} | |
} | |
class B extends A { | |
override def x: Int = macro B.impl | |
} | |
// Exiting paste mode, now interpreting. | |
warning: there was one deprecation warning; re-run with -deprecation for details | |
import scala.language.experimental.macros | |
import scala.reflect.macros.Context | |
defined trait A | |
defined object B | |
defined class B | |
scala> val b = new B | |
b: B = B@a7d060f | |
scala> b.x | |
res0: Int = 2 | |
scala> (b: A).x | |
java.lang.AbstractMethodError: B.x()I | |
... 33 elided |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://issues.scala-lang.org/browse/SI-8949