Skip to content

Class extended to a trait fail on invokespecial when mixed in. #1501

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

Closed
nicolasstucki opened this issue Sep 8, 2016 · 2 comments
Closed
Assignees

Comments

@nicolasstucki
Copy link
Contributor

class A {
  def foo: Int = 1
}

trait B extends A

abstract class D {
  def foo: Int
}

class C extends D with B

object Test {
  def main(args: Array[String]): Unit = {
    println(new C().foo)
  }
}

will fail with:

java.lang.VerifyError: Bad invokespecial instruction: current class isn't assignable to reference class.
Exception Details:
  Location:
    C.foo()I @1: invokespecial
  Reason:
    Error exists in the bytecode
  Bytecode:
    0x0000000: 2ab7 0013 ac                           

    at Test$.main(foo.scala:16)
    at Test.main(foo.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at scala.reflect.internal.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:70)
    at scala.reflect.internal.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
    at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:101)
    at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:70)
    at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
    at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:22)
    at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39)
    at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:29)
    at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39)
    at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:65)
    at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87)
    at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98)
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

@DarkDimius
Copy link
Contributor

@nicolasstucki, this shouldn't compile at all.

in your example C has two superclasses - A and D.

@nicolasstucki
Copy link
Contributor Author

@DarkDimius I was trying to reproduce the bug we looked at earlier and wasn't able. I got this while fuzzing the code a bit to try to reproduce it.

odersky added a commit to dotty-staging/dotty that referenced this issue Feb 2, 2017
We need to check a coherence condition between the superclass
of a trait and the superclass of an inheriting class or trait.
@odersky odersky self-assigned this Feb 2, 2017
smarter added a commit that referenced this issue Feb 13, 2017
Fix #1501 - Check trait inheritance condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants