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
object may override a def causing ClassCastException in unrelated code #5429
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5429?orig=1 |
@paulp said: class A2 {
def m2: Any = 5
}
class B2 extends A2 {
override object m2
} I've fixed the overriding bug, will check in shortly. |
@paulp said: |
@paulp said: % scala -Yoverride-objects
Welcome to Scala version 2.10.0.rdev-4299-2012-01-30-g366fae9 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :paste
// Entering paste mode (ctrl-D to finish)
class A2 { object m2 }
class B2 extends A2 { override object m2 }
// Exiting paste mode, now interpreting.
defined class A2
defined class B2 |
@soc said: class A {
object m { override def toString = "object m" }
}
class B extends A {
def m() = "def m"
}
(new B).m() java.lang.VerifyError: class B overrides final method m.()LA$m$;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at scala.tools.nsc.interpreter.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at scala.tools.nsc.interpreter.AbstractFileClassLoader.scala$tools$nsc$util$ScalaClassLoader$$super$loadClass(AbstractFileClassLoader.scala:18)
at scala.tools.nsc.util.ScalaClassLoader$class.loadClass(ScalaClassLoader.scala:63)
at scala.tools.nsc.interpreter.AbstractFileClassLoader.loadClass(AbstractFileClassLoader.scala:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at .<init>(<console>:10)
at .<clinit>(<console>)
at .<init>(<console>:11)
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:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:761)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$13.apply(IMain.scala:1002)
at scala.tools.nsc.interpreter.Line.scala$tools$nsc$interpreter$Line$$runAndSetState(Line.scala:41)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:47)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:19)
at java.lang.Thread.run(Thread.java:722) |
Rike-Benjamin Schuppner (debilski) said: |
@soc said: I also checked it with |
@paulp said: |
@paulp said: |
Given some class with a method
it is currently possible to override this method with an object definition:
The compiler won't complain about this (and I'm not sure what the specification says about this specific situation), however the code will break wherever A is expected:
As a possibly related phenomenon: It is currently not possible to override a parentheses-less def with an object.
Related: https://groups.google.com/forum/#!topic/scala-user/TOuQ2-Jr_R8
Related: http://stackoverflow.com/questions/7584400/overriding-a-method-with-an-object
The text was updated successfully, but these errors were encountered: