Skip to content

No static $init$ in pure trait extending impure trait #9970

Closed
@bishabosha

Description

@bishabosha

Minimized code

trait IOApp {
  protected val foo = 23

  def run(args: List[String]): Int

  final def main(args: Array[String]): Unit = {
    sys.exit(run(args.toList))
  }

}
object IOApp {
  trait Simple extends IOApp {
    def run: Unit

    final def run(args: List[String]): Int = {
      run
      0
    }
  }
}

Output

IOApp compiled by dotty 0.27.0-RC1:

public static interface IOApp.Simple
extends IOApp {
    public void run();

    public static int run$(IOApp.Simple $this, List args) {
        return $this.run((List<String>)args);
    }

    @Override
    default public int run(List<String> args) {
        this.run();
        return 0;
    }
}

Expectation

IOApp compiled by Scala 2.13.3:

public static interface IOApp.Simple
extends IOApp {
    public void run();

    public static /* synthetic */ int run$(IOApp.Simple $this, List args) {
        return $this.run((List<String>)args);
    }

    @Override
    default public int run(List<String> args) {
        this.run();
        return 0;
    }

    public static void $init$(IOApp.Simple $this) {
    }
}

This means we can't use cats-effect-3 (compiled by dotty) in scala 2.13, as extending IOApp.Simple expects the static IOApp.Simple.$init$ method to exist

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions