Skip to content

Missing trait initialisers in certain cases, compared to Scala 2 #10839

Closed
@dwijnand

Description

@dwijnand

Minimized code

class A
trait B extends A {
  def foo = 2
}

or

trait A {
  def foo: Int
}
trait B extends A {
  def foo = 2
}

Output

$ echo 'class A; trait B extends A { def foo = 2 }' > A.scala && scalac3 A.scala && javap B
Compiled from "A.scala"
public interface B {
  public static int foo$(B);
  public default int foo();
}
$
$ echo 'trait A { def foo: Int }; trait B extends A { def foo = 2 }' > A.scala && scalac3 A.scala && javap B
Compiled from "A.scala"
public interface B extends A {
  public static int foo$(B);
  public default int foo();
}

Expectation

Same as Scala 2:

$ echo 'class A; trait B extends A { def foo = 2 }' > A.scala && scalac A.scala && javap B
Compiled from "A.scala"
public interface B {
  public static int foo$(B);
  public default int foo();
  public static void $init$(B);
}
$
$ echo 'trait A { def foo: Int }; trait B extends A { def foo = 2 }' > A.scala && scalac A.scala && javap B
Compiled from "A.scala"
public interface B extends A {
  public static int foo$(B);
  public default int foo();
  public static void $init$(B);
}

This came from some test cases in MiMa where changes within such hierarchies cause binary incompatibilities. I'd love if they didn't, but I think Scalac 2 has good reason to be the way it is and I believe we don't want to deviate from that in Scala 3. So perhaps this one is a 3.0 blocker...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions