Skip to content
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

ClassFormatError with local definitions #5252

Open
scabug opened this issue Nov 30, 2011 · 10 comments
Open

ClassFormatError with local definitions #5252

scabug opened this issue Nov 30, 2011 · 10 comments
Labels
bytecode fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) minimized regression
Milestone

Comments

@scabug
Copy link

scabug commented Nov 30, 2011

The following produces a bad classfile, both with 2.9.1 and latest nightly.

object test {
  def main(args: Array[String]): Unit = {
    var out = 1
    trait Trait {
      def foo(): Unit = {
        out += 1
      }
    }
    case class C(parent: Trait) extends Trait {}
    C(null)
  }
} 

test.main(Array())

Error is: java.lang.ClassFormatError: Duplicate field name&signature in class file test$C$2

@scabug
Copy link
Author

scabug commented Nov 30, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5252?orig=1
Reporter: @lrytz
Affected Versions: 2.11.0-M8, 2.12.0
See #1960, #3994

@scabug
Copy link
Author

scabug commented Nov 30, 2011

@lrytz said:
that's the only other ticket that has the same error message

@scabug
Copy link
Author

scabug commented May 20, 2012

@retronym said:
Reduced a step or two:

object Test {

  {
    val out = 0
    trait Trait {
      def foo {
        out
      }
    }

    class C extends Trait {
      def copy { new C }
    }

    new C
  }

  def main(args: Array[String]) {
  }
}

@scabug
Copy link
Author

scabug commented May 20, 2012

@retronym said:
Seems to be a regression fro 2.7.7 to 2.8.0.

@scabug
Copy link
Author

scabug commented Jun 5, 2012

@magarciaEPFL said:
Right after flatten there are two field declarations with the same name and type (val out$1: Int = _; ), one each in the following classes:

  • class Test$C$1 extends Object with Test$Trait$1
  • abstract trait Test$Trait$1$class extends Object with Test$Trait$1
  class Test$C$1 extends Object with Test$Trait$1 {
    def copy(): Unit = {
      new Test$C$1(Test$C$1.this.out$1);
      ()
    };
    <synthetic> <paramaccessor> private[this] val out$1: Int = _; /* <---------------- in the composed class */
    def <init>(out$1: Int): Test$C$1 = {
      Test$C$1.this.out$1 = out$1;
      Test$C$1.super.<init>();
      Test$C$1.this.$asInstanceOf[Test$Trait$1$class]()./*Test$Trait$1$class*/$init$(out$1);
      ()
    }
  };
  abstract trait Test$Trait$1$class extends Object with Test$Trait$1 {
    def foo(): Unit = {
      Test$Trait$1$class.this.out$1;
      ()
    };
    <synthetic> <paramaccessor> private[this] val out$1: Int = _; /* <---------------- in the implementation class */
    def /*Test$Trait$1$class*/$init$(out$1: Int): Unit = {
      Test$Trait$1$class.this.out$1 = out$1;
      ()
    }
  }

The Mixin phase lumps both fields in class Test$C$1

  class Test$C$1 extends Object with Test$Trait$1 {

    <synthetic> <stable> <accessor> <paramaccessor> def out$1(): Int = Test$C$1.this.out$1;  /* <---------------- (1 of 2)  */

    private[this] val out$1: Int = _;
    <synthetic> <accessor> <paramaccessor> def Test$Trait$1$_setter_$out$1_=(x$1: Int): Unit = Test$C$1.this.out$1 = x$1;
    def foo(): Unit = Test$Trait$1$class.foo(Test$C$1.this);
    def copy(): Unit = {
      new Test$C$1(Test$C$1.this.out$1);
      ()
    };

    <synthetic> <paramaccessor> private[this] val out$1: Int = _;                            /* <---------------- (2 of 2)  */

    def <init>(out$1: Int): Test$C$1 = {
      Test$C$1.this.out$1 = out$1;
      Test$C$1.super.<init>();
      Test$Trait$1$class./*Test$Trait$1$class*/$init$(Test$C$1.this, out$1);
      ()
    }
  }

That's why javap -private Test\$C\$1 shows:

public class Test$C$1 extends java.lang.Object implements Test$Trait$1{
    private final int out$1;
    private final int out$1;
    public int out$1();
    public void Test$Trait$1$_setter_$out$1_$eq(int);
    public void foo();
    public void copy();
    public Test$C$1(int);
}

@scabug
Copy link
Author

scabug commented Jun 11, 2012

@retronym said:
More mangling seems to be called for here. Might be worth considering #3994 at the same time.

@scabug
Copy link
Author

scabug commented Sep 26, 2016

@lrytz said:
2.12.0-RC1 gives an error message:

A.scala:60: error: parameter 'out$1' requires field but conflicts with value out$1 in trait Trait$1
    var out = 1
        ^
one error found

@scabug
Copy link
Author

scabug commented Sep 26, 2016

@sarahgerweck
Copy link

sarahgerweck commented Apr 18, 2017

Just want to chime in that I am getting the "duplicate field name&signature" issue in Scala 2.12.x with code that has worked flawlessly for a long time in Scala 2.11.x. Things seems to be worse in 2.12 than they were in 2.11.

@szeiger szeiger modified the milestones: 2.13.0-M3, 2.13.0-M2 Jul 20, 2017
@adriaanm adriaanm modified the milestones: 2.13.0-M3, 2.13.0-M4 Jan 30, 2018
@lrytz lrytz removed this from the 2.13.0-M4 milestone Apr 23, 2018
@lrytz lrytz added this to the 2.13.0-M5 milestone Apr 23, 2018
@retronym retronym modified the milestones: 2.13.0-M5, Backlog Aug 8, 2018
@adriaanm adriaanm removed their assignment Sep 28, 2018
@scala scala deleted a comment from scabug Mar 6, 2023
@scala scala deleted a comment from scabug Mar 6, 2023
@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Mar 6, 2023
@SethTisue
Copy link
Member

#8984 has an additional reproduction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bytecode fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) minimized regression
Projects
None yet
Development

No branches or pull requests

7 participants