-
Notifications
You must be signed in to change notification settings - Fork 1.1k
java interop: inherits unrelated defaults for $init$() from types #8599
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
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
decompile using Procyon v0.5.36 to compare: % curl -Lo pd.jar https://bitbucket.org/mstrobel/procyon/downloads/procyon-decompiler-0.5.36.jar
% java -jar pd.jar target/scala-0.23/classes/A.class target/scala-0.23/classes/Scala.class
public interface A {
default void $init$() { }
int a();
default int initial$a() {
return 0;
}
}
public class Scala implements B, A {
private final int b;
private final int a;
public Scala() {
this.b = super.initial$b();
super.$init$();
this.a = super.initial$a();
super.$init$();
}
@Override public int b() {
return this.b;
}
@Override public int a() {
return this.a;
}
}
% java -jar pd.jar target/scala-2.13/classes/A.class target/scala-2.13/classes/Scala.class
@ScalaSignature(...)
public interface A {
void A$_setter_$a_$eq(final int x$1);
int a();
default void $init$(final A $this) {
$this.A$_setter_$a_$eq(0);
}
}
@ScalaSignature(...)
public class Scala implements B, A {
private int a;
private int b;
@Override public int a() {
return this.a;
}
@Override public void A$_setter_$a_$eq(final int x$1) {
this.a = x$1;
}
@Override public int b() {
return this.b;
}
@Override public void B$_setter_$b_$eq(final int x$1) {
this.b = x$1;
}
public Scala() {
B.$init$();
A.$init$();
Statics.releaseFence();
}
} Note in dotty case (target/scala-0.23):
|
This might go away once we switch to the old trait encoding scheme |
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 28, 2020
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 28, 2020
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 28, 2020
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 29, 2020
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 29, 2020
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 30, 2020
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 31, 2020
giabao
added a commit
to ohze/akka
that referenced
this issue
Mar 31, 2020
sjrd
added a commit
to dotty-staging/dotty
that referenced
this issue
Nov 26, 2020
Concrete trait methods are encoded as two methods in the back-end: * a default method containing the real body, and * a static forwarder, to use for super calls (due to JVM reasons). Previously, we did that also for the trait initializer methods `$init$`. However, that causes unrelated default methods to be inherited by Scala classes that extend several traits. In turn, that prevents Java classes from extending such classes. Now, for the `$init$` methods, instead of creating a static forwarder, we *move* the entire body to a static method. Therefore, we only create a static method, and no default method. This corresponds to what scalac does as well (both what we do and how we do it), although the previous "discrepancy" was not causing any incompatibility between Scala 2 and 3 per se.
sjrd
added a commit
to dotty-staging/dotty
that referenced
this issue
Nov 27, 2020
Concrete trait methods are encoded as two methods in the back-end: * a default method containing the real body, and * a static forwarder, to use for super calls (due to JVM reasons). Previously, we did that also for the trait initializer methods `$init$`. However, that causes unrelated default methods to be inherited by Scala classes that extend several traits. In turn, that prevents Java classes from extending such classes. Now, for the `$init$` methods, instead of creating a static forwarder, we *move* the entire body to a static method. Therefore, we only create a static method, and no default method. This corresponds to what scalac does as well (both what we do and how we do it), although the previous "discrepancy" was not causing any incompatibility between Scala 2 and 3 per se.
sjrd
added a commit
that referenced
this issue
Nov 27, 2020
Fix #8599: Emit trait init methods only as static methods.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
minimized code
Compilation output
expectation
compile successfully as in scala 2
The text was updated successfully, but these errors were encountered: