Skip to content

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

Closed
@SethTisue

Description

@SethTisue

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();
    }
...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions