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
Eclipse compiler can determine intended varargs method while javac complains method ambiguous #370
Comments
|
Generally, overload resolution happens in phases such when one phase succeeds, the next phase is never consulted. The first phase ("Applicable by Strict Invocation") does not allow an conversions like (un)boxing. At a naive look this could justify why the first method is chosen over the second. However, even the first method is not a "Strict Invocation" but a "Variable Arity Invocation" (the Someone would have to spend time to debug the compiler with the corresonding JLS paragraphs on the table. A key piece will probably be https://docs.oracle.com/javase/specs/jls/se19/html/jls-18.html#jls-18.5.4. OTOH, overloading is one of the best means to not only confuse compilers but also programmers. Overloading with generic methods likely comes with more complexity then what average users of those methods can handle. Add varargs plus boxing to the mix and you've got one of the hardest riddles the language has to offer. Method names are cheap, the complexity of overloading is not - far from it. |
|
Something like this also happens with when you call the method with something like Eclipse wants to use the method in class B while javac is not happy. |
At compliance 1.7 reports the same ambiguity, only since 1.8 the example is accepted. However, the original issue was about a combination of varargs plus boxing in overloading resolution. Since the newer example has no boxing in the picture please file a new issue. Thanks. |
|
Anyone planning to investigate these issues may want to have a look at https://bugs.eclipse.org/bugs/show_bug.cgi?id=457233#c2 where I collected some links to bug fixes of JLS, that may not yet have found their way into ecj. |
Transfer of Bug 578410
Problem
Eclipse compiler can infer primitive varargs overload while javac errors with "reference to method is ambiguous". This leads to nice little surprises when the build pipeline in Jenkins then fails unexpectedly.
Example
While
eclipseccompiles this code without problems, bindind the call tomethodto theint...overload,javacfails with the following error messageThe compiled class will output "int array" in all cases where compilation was successful.
Assuming the behaviour of the
javacis correct according to the Java language specification (the code does only compile in JDK 1.5 and 1.6; JDK 1.7 - 20 give the above error) theneclipsecshould also give an error on this line.Tested with
Eclipse SDK
Version: 2022-12 (4.26)
Build id: I20220904-1800
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
openjdk version "1.7.0_75"
OpenJDK Runtime Environment (build 1.7.0_75-b13)
OpenJDK Client VM (build 24.75-b04, mixed mode)
... some other versions in between ...
openjdk version "20-ea" 2023-03-21
OpenJDK Runtime Environment (build 20-ea+13-860)
OpenJDK 64-Bit Server VM (build 20-ea+13-860, mixed mode, sharing)
The text was updated successfully, but these errors were encountered: