-
Notifications
You must be signed in to change notification settings - Fork 136
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
[Enhanced Switch] Problem with switch and enums - incorrect duplicate case error #3344
Comments
Reproduced the symptoms as described on 4.33. On master we actually refuse to compile the program incorrectly complaining about I know the problem and will shortly propose a fix. |
I have included a fix and regression test here : #3310 Unfortunately, it is too late for 4.34 which is almost about to sail. You can grab an integration build after this is merged. |
Thank you very much for the prompt fix! |
You are welcome! |
I have a piece of code which switches on objects of an interface. The interface is implemented by two enums, and the switch has objects of both enums. In one case, the enum objects are referenced with the enum name (MyEnum.A1), in the other, the enum objects are statically imported and referenced only with the enum name. When I compile with Eclipse 2024-9, the two cases behave differently. When I compile with javac from Java 21, they behave the same.
I execute the code with java from Java 21 in both cases.
For compiling with Java 21, I copied the source to some place outside of the workspace (directory java21), and compile it with:
javac -g java21\Main.java java21\p\X.java java21\p\A.java java21\p\B.java
I then run the code from the Eclipse compiler and the Java compiler with the Java 21 VM:
java -cp workspace\testli\bin Main
java -cp java21 Main
This is the expected output, which I get when I compile and run the code in Java 21:
A1 -> A1, A1
A2 -> A2, A2
B1 -> B1, B1
B2 -> B2, B2
This is what I get when I run the Eclipse compiled code in Eclipse or in Java 21:
A1 -> unknown, A1
A2 -> unknown, A2
B1 -> unknown, B1
B2 -> unknown, B2
It looks like the enum literals are not matched when they are statically imported.
Here is the source code:
Main.zip
I disassembled both Main class files, and the interface file, and one of the enums, and attach them here:
Disassembled.zip
Versions:
Eclipse IDE for Java Developers (includes Incubating components)
Version: 2024-09 (4.33.0)
Build id: 20240905-0614
The project in eclipse also uses the same MS OpenJDK with compliance level 21.
The text was updated successfully, but these errors were encountered: