-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
No static forwarder methods in companion of trait #13572
Comments
smarter
changed the title
Bytecode Difference when Object + Trait with the same name between Scala 2.13 and 3.x
No static forwarder methods in companion of trait
Sep 21, 2021
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Sep 21, 2021
Same change implemented five years ago in Scala 2: scala/scala#5131 Fixes scala#13572.
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Sep 21, 2021
Same change implemented five years ago in Scala 2: scala/scala#5131 Fixes scala#13572.
jlprat
added a commit
to jlprat/kafka
that referenced
this issue
Sep 21, 2021
jlprat
added a commit
to jlprat/kafka
that referenced
this issue
Sep 21, 2021
anatoliykmetyuk
pushed a commit
to dotty-staging/dotty
that referenced
this issue
Sep 27, 2021
Same change implemented five years ago in Scala 2: scala/scala#5131 Fixes scala#13572.
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Oct 5, 2021
Same change implemented five years ago in Scala 2: scala/scala#5131 Fixes scala#13572. This PR was backported to 3.1.0-RC3 in scala#13616, this lets us bump the previousDottyVersion to make the mima checks pass even though this PR introduces new public member (and while we're at it, we can reset the mima filter list).
olsdavis
pushed a commit
to olsdavis/dotty
that referenced
this issue
Apr 4, 2022
Same change implemented five years ago in Scala 2: scala/scala#5131 Fixes scala#13572. This PR was backported to 3.1.0-RC3 in scala#13616, this lets us bump the previousDottyVersion to make the mima checks pass even though this PR introduces new public member (and while we're at it, we can reset the mima filter list).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First of all sorry if this was already discussed or if it's intentional, but I encountered a discrepancy in bytecode generation between Scala 2.13 and 3.x.
In Scala 2.13 when an
object
and atrait
shared the same name, all methods belonging to theobject
were copied over to the class representing the trait as static ones.This bit is important for the Java interoperability aspect, as the Scala 2.13 bytecode made it easy to use Scala classes from Java, while in Scala 3, we would need to fall back to referencing members of the object using the synthetic name (class name plus $ sign).
Note that when the combination is an
object
and aclass
the bytecode generated is compatible with the one generated for Scala 2.13, for more details see the reproducer here.Compiler version
Scala 3.0.2 and 3.1.0-RC2
Minimized code
You can find a reproducer here
Output
If we inspect the bytecode of the trait (ObjectTraitPair.class) we see:
javap ObjectTraitPair.class
Expectation
In Scala 2.13 the same trait's bytecode would be
Please note the missing
public static java.lang.String Constant();
on the Scala 3 bytecode.Workaround
When this needs to be used from Java, the workaround can be this:
The text was updated successfully, but these errors were encountered: