Skip to content

dotc may generate duplicate super accessors, resulting in ClassFormatError #756

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
SethTisue opened this issue Aug 13, 2015 · 1 comment
Closed

Comments

@SethTisue
Copy link
Member

here's the input code:

~/dotty % cat S.scala
trait T { def foo: Int = 3 }
trait T1 extends T { override def foo = super.foo }
trait T2 extends T { override def foo = super.foo }
object C extends T2 with T1 {
  def main(args: Array[String]) = ()
}

with Scala 2.11.7, no error:

~/dotty % /usr/local/scala-2.11.7/bin/scalac S.scala
~/dotty % java -classpath . C

but with Dotty:

~/dotty % rm *.class
~/dotty % bin/dotc S.scala
~/dotty % java -classpath . C
Exception in thread "main" java.lang.ClassFormatError: Duplicate method name&signature in class file C$
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
...

the problem is that the generated code has two identical methods named super$foo:

~/dotty % cfr-decompiler C\$.class
...
public final class C$
implements T,
T2,
T1 {
...
    @Override
    public /* synthetic */ int super$foo() {
        return super.foo();
    }
    @Override
    public /* synthetic */ int super$foo() {
        return super.foo();
    }
...
}
@odersky
Copy link
Contributor

odersky commented Aug 13, 2015

Thanks Seth!

On Thu, Aug 13, 2015 at 4:04 PM, Seth Tisue [email protected]
wrote:

here's the input code:

~/dotty % cat S.scala
trait T { def foo: Int = 3 }
trait T1 extends T { override def foo = super.foo }
trait T2 extends T { override def foo = super.foo }
object C extends T2 with T1 {
def main(args: Array[String]) = ()
}

with Scala 2.11.7, no error:

~/dotty % /usr/local/scala-2.11.7/bin/scalac S.scala
~/dotty % java -classpath . C

but with Dotty:

~/dotty % rm *.class
~/dotty % bin/dotc S.scala
~/dotty % java -classpath . C
Exception in thread "main" java.lang.ClassFormatError: Duplicate method name&signature in class file C$
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
...

CFR shows what the problem is:

~/dotty % cfr-decompiler C$.class
...
public final class C$
implements T,
T2,
T1 {
public static final C$ MODULE$;

public static {
    new C$();
}

public C$() {
    MODULE$ = this;
}

@Override
public /* synthetic */ int super$foo() {
    return super.foo();
}

@Override
public /* synthetic */ int super$foo() {
    return super.foo();
}

@Override
public int foo() {
    return super.foo();
}

public void main(String[] args) {
}

}

note the two identical super$foo methods.


Reply to this email directly or view it on GitHub
#756.

Martin Odersky
EPFL

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

2 participants