-
Notifications
You must be signed in to change notification settings - Fork 1.1k
final val in trait should not be encoded as abstract method #8602
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
@sjrd's work on switching back to scalac's trait encoding might fix this as well. |
The result is now different but still not java-friendly: Compiled from "Scala.scala"
public interface Scala {
public static void $init$(Scala);
public default void $init$();
public abstract int x();
public abstract void Scala$_setter_$x_$eq(int);
} |
So, this is really really tricky. It's not the first time that we run into trouble with constant expression The big problem is that, when we get to the phases that perform mixin composition and allocation of fields, in dotc we have lost the knowledge of what was a constant expression trait Foo {
final val foo = 5
final val foobar: Int = 5
val bar: Option[Int] = Some(5)
} by the time we get to package <empty> {
@scala.annotation.internal.SourceFile("tests\\run\\hello.scala") trait Foo()
extends
Object {
final def foo(): Int = 5
final def foobar(): Int = 5
def bar(): Option = Some.apply(scala.Int.box(5))
}
} Yet, for scalac they are different. scalac can do different things because the decision to allocate fields is done before erasure, where we still see the My conclusion at this point is that I need to preserve the information that a |
This matches what Scala 2 does (addressing binary compatibility with Scala 2) and allows a trait with only such `final val`s to be extended from Java.
This matches what Scala 2 does (addressing binary compatibility with Scala 2) and allows a trait with only such `final val`s to be extended from Java.
It turns out time travel does the trick, of course 🤦♂️ |
…l-val Fix #8602: Do not create mixins for constant-expression final vals.
minimized code
Compilation output
expectation
compile successfully as in scala 2
inspect
The text was updated successfully, but these errors were encountered: