Skip to content

object overriding a val: duplicate class error #8663

Open
@scabug

Description

@scabug
class Test
trait A {
  val a: Test = new Test
}
trait B extends A {
  override object a extends Test
}

object Test extends App {
  val b = new B{}
}
qscalac -Xprint:erasure sandbox/test.scala && qscala Test
[[syntax trees at end of                   erasure]] // test.scala
package <empty> {
  class Test extends Object {
    def <init>(): Test = {
      Test.super.<init>();
      ()
    }
  };
  abstract trait A extends Object {
    <stable> <accessor> def a(): Test
  };
  abstract trait B extends Object with A {
    object a extends Test {
      def <init>($outer: B): B.this.a.type = {
        a.super.<init>();
        ()
      };
      <synthetic> <paramaccessor> <artifact> private[this] val $outer: B = _;
      <synthetic> <stable> <artifact> def $outer(): B = a.this.$outer
    };
    override <stable> def a(): B#a.type
  };
  object Test extends Object with App {
    def <init>(): Test.type = {
      Test.super.<init>();
      Test.this.$asInstanceOf[App$class]()./*App$class*/$init$();
      ()
    };
    private[this] val b: B = {
      final class $anon extends Object with B {
        def <init>(): <$anon: B> = {
          $anon.super.<init>();
          $anon.this.$asInstanceOf[A$class]()./*A$class*/$init$();
          $anon.this.$asInstanceOf[B$class]()./*B$class*/$init$();
          ()
        };
        override <stable> <bridge> <artifact> def a(): Test = $anon.this.a()
      };
      new <$anon: B>()
    };
    <stable> <accessor> def b(): B = Test.this.b
  };
  abstract trait A$class extends Object with A {
    def /*A$class*/$init$(): Unit = {
      ()
    };
    private[this] val a: Test = new Test();
    <stable> <accessor> def a(): Test = A$class.this.a
  };
  abstract trait B$class extends Object with A$class with B {
    def /*B$class*/$init$(): Unit = {
      ()
    };
    @volatile <synthetic> var a$module: B#a.type = _;
    override <stable> def a(): B#a.type = new B#a.type(B$class.this)
  }
}

java.lang.ClassFormatError: Duplicate method name&signature in class file Test$$anon$1
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions