New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AbstractMethodError when override using macro #8949
Comments
Imported From: https://issues.scala-lang.org/browse/SI-8949?orig=1 |
@retronym said: |
kenji yoshida said: 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
object A {
def impl(c: Context): c.Expr[Int] = {
import c.universe._
c.Expr[Int](Literal(Constant(2)))
}
}
class A {
def x: Int = macro A.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 object A
defined class A
scala> val a0 = new A
a0: A = A@34aad3ab
scala> a0.x
res0: Int = 2
scala> val a1: {def x: Int} = a0
a1: AnyRef{def x: Int} = A@34aad3ab
scala> a1.x
warning: there was one feature warning; re-run with -feature for details
java.lang.NoSuchMethodException: A.x()
at java.lang.Class.getMethod(Class.java:1665)
at .reflMethod$Method1(<console>:16)
... 33 elided
|
kenji yoshida said: Welcome to Scala 2.12.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions for evaluation. Or try :help.
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.
<console>:20: warning: type Context in package macros is deprecated (since 2.11.0): use blackbox.Context or whitebox.Context instead
def impl(c: Context): c.Expr[Int] = {
^
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@552cede7
scala> b.x
res0: Int = 2
scala> (b: A).x
res1: Int = 1 |
The text was updated successfully, but these errors were encountered: