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
Don't emit forwarder in mirror class for bridge methods #6531
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lrytz
force-pushed
the
b10812
branch
2 times, most recently
from
April 17, 2018 15:44
cdf1663
to
19717bf
Compare
When overriding a (concrete) method in an object with a varying signature, make sure only one static forwarder method is emitted in the mirror class, not an additional one with the signature of the bridge. class A { def f: Object = null } object B extends A { override def f: String = "b" } `typeOf[B.type].membersBasedOnFlags(BRIDGE, METHOD)` after erasure works correctly in that it doesn't return the bridge in B, but it returns both `A.f` and `B.f`. This commit makes it run in an earlier phase.
changed base to 2.13.x |
ping for review, @retronym |
retronym
approved these changes
May 13, 2018
lrytz
added a commit
to lrytz/scala
that referenced
this pull request
Aug 8, 2018
They were accidentally dropped in scala#6531. Fixes scala/bug#11057.
eed3si9n
added a commit
to eed3si9n/scala
that referenced
this pull request
Aug 11, 2018
Fixes scala/bug#11061 Ref scala/bug#10812 On 2.13.x branch scala#6531 removed the forwarder for bridge methods. I would like to do same in 2.12.x since Java 11-ea started to find them ambiguous as seen in akka/akka#25449 / scala/bug#11061. To keep binary compatibility, I am still emitting the forwarder for bridge methods, but with `ACC_BRIDGE` flag.
eed3si9n
added a commit
to eed3si9n/scala
that referenced
this pull request
Aug 20, 2018
Fixes scala/bug#11061 Ref scala/bug#10812 On 2.13.x branch scala#6531 removed the mirror class forwarders for bridge methods. I would like to do same in 2.12.x since Java 11-ea started to find them ambiguous as seen in akka/akka#25449 / scala/bug#11061. To keep binary compatibility, I am still emitting the forwarders for bridge methods, but with `ACC_BRIDGE` flag.
eed3si9n
added a commit
to eed3si9n/scala
that referenced
this pull request
Aug 20, 2018
Fixes scala/bug#11061 Ref scala/bug#10812 On 2.13.x branch scala#6531 removed the mirror class forwarders for bridge methods. I would like to do same in 2.12.x since Java 11-ea started to find them ambiguous as seen in akka/akka#25449 / scala/bug#11061. To keep binary compatibility, I am still emitting the forwarders for bridge methods, but with `ACC_BRIDGE` flag.
see also scala/bug#11061 |
lrytz
added a commit
to lrytz/scala
that referenced
this pull request
Nov 27, 2018
In 2.12.6 and before, the Scala compiler emits static forwarders for bridge methods in top-level modules. These forwarders are emitted by mistake, the filter to exclude bridges did not work as expected. These bridge forwarders make the Java compiler on JDK 11 report ambiguity errors when using static forwarders (scala/bug#11061). PR scala#7035 fixed this for 2.12.7 by adding the `ACC_BRIDGE` flag to static forwarders for bridges. We decided to keep these bridges for binary compatibility. However, the new flag causes the eclipse Java compiler (and apparently also IntelliJ) to report ambiguity errors when using static forwarders (scala/bug#11271). In 2.13.x the Scala compiler no longer emits static forwarders for bridges (PR scala#6531). This PR brings the same behavior to 2.12.8. This change breaks binary compatibility. However, in the examples we tested, the Java compiler emits references to the non-bridge methods, so compiled code continues to work if a library is replaced by a new version that doesn't have forwarders for bridges: ``` $> cat T.scala class A[T] { def get: T = ??? } object T extends A[String] { override def get: String = "hi" } $> ~/scala/scala-2.12.7/bin/scalac T.scala ``` Generates two forwarders in `T.class` ``` // access flags 0x49 public static bridge get()Ljava/lang/Object; // access flags 0x9 public static get()Ljava/lang/String; ``` ``` $> javac -version javac 1.8.0_181 $> cat Test.java public class Test { public static void main(String[] args) { System.out.println(T.get()); } } $> javac Test.java ``` Generates in Test.class ``` INVOKESTATIC T.get ()Ljava/lang/String; ```
10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When overriding a (concrete) method in an object with a varying
signature, make sure only one static forwarder method is emitted in the
mirror class, not an additional one with the signature of the bridge.
typeOf[B.type].membersBasedOnFlags(BRIDGE, METHOD)
after erasure workscorrectly in that it doesn't return the bridge in B, but it returns
both
A.f
andB.f
. This commit makes it run in an earlier phase.Fixes scala/bug#10812