-
Notifications
You must be signed in to change notification settings - Fork 21
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
JDK 11 gets confused about override methods: reference to X is ambiguous #11061
Comments
Perhaps already fixed by scala/scala#6531 / #10812 |
That's a great news. |
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.
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.
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.
I upgrade to 2.12.7, but also have this problem, I use jdk 11, scala 2.12.7 and akka 2.5.17 |
code repo https://github.com/oryjk/scala_build_with_jdk11.git, sbt compile |
@SethTisue link to akka/akka#25777 |
ah, makes sense, the bug is fixed in 2.12.7, but a library such as Akka won't have the fix until they publish a release that was built with 2.12.7. |
Maybe we should advertise that all libraries compiled and published with Scala 2.12.(0 - 6) are affected with this bug, if they interface with |
I added " #6531 improve callability of some methods from Java" to the "Improved Java 9+ support" bullet at https://github.com/scala/scala/releases/tag/v2.12.7 |
also announced at https://contributors.scala-lang.org/t/library-authors-rebuild-on-2-12-7-to-improve-callability-from-java-on-jdk-11/2465 I think it's probably niche enough that a scala_lang tweet isn't needed. |
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; ```
This was originally reported by @chbatey in akka/akka#25449.
steps
Clone https://github.com/eed3si9n/override-in-jdk11
problem
expectation
It compiles.
note
It works on JDK 8, but note that there are two
get
when you look at it using javap:project/build.properties
build.sbt
src/main/scala/example/TestObject.scala
src/main/java/example/Test.java
The text was updated successfully, but these errors were encountered: