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
Compiler allows to super-call an abstract method. This leads to an AbstractMethodError at runtime. #4989
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4989?orig=1 |
@retronym said (edited on May 13, 2012 8:35:05 PM UTC): scala> abstract class A { def a() }; abstract class B extends A { def a() }
defined class A
defined class B
scala> object C extends B { override def a() = super.a() }
<console>:9: error: method a in class B is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override'
object C extends B { override def a() = super.a() }
^
scala> import reflect.{mirror => m}
import reflect.{mirror=>m}
scala> m.classToType(classOf[B]).member(m.newTermName("a")).modifiers
res1: Set[scala.reflect.api.Modifier] = Set(deferred)
scala> class A { def a() {} }; abstract class B extends A { def a() }
defined class A
defined class B
scala> object C extends B { override def a() = super.a() }
defined module C
scala> m.classToType(classOf[B]).member(m.newTermName("a")).modifiers
res2: Set[scala.reflect.api.Modifier] = Set()
scala> C.a()
java.lang.AbstractMethodError: A.a()V
at C$.a(<console>:10)
at .<init>(<console>:12)
at .<clinit>(<console>) Key question: When does the symbol for |
@paulp said:
It doesn't. When you request the member of B called a, you get the symbol defined in A, not in B, because concrete always overrides abstract. If you want B#a, use decl (or I guess it's called declaration in the library.) |
@retronym said: |
The following program compiles with no error message. At runtime, a
java.lang.AbstractMethodError
is thrown.The point is, that method
print
defined in classA
is overwritten in classB
with an abstract definition.In class
C
, which extendsB
, this abstract method is invoked with a super call. I expected a compilation erroron this super call.
The text was updated successfully, but these errors were encountered: