eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
165 stars 130 forks source link

[Switch Expressions][Bugzilla - 565907] [14] case with constant switch expression flags error #3290

Open srikanth-sankaran opened 1 day ago

srikanth-sankaran commented 1 day ago

Brought forward from https://bugs.eclipse.org/bugs/show_bug.cgi?id=565907

Follow up from bug 565844 comment 6:

consider the code: case switch (2) {default ->1} ->

This has a constant value and the compiler should not flag an error.

srikanth-sankaran commented 1 day ago

Better test case:

public class X {
    public static void main(String [] args) {
        switch (10) {
            case switch (10) { default -> 10; } :
                System.out.println("Should not compile as per 15.29 & 14.11.1");
        }
    }
}
srikanth-sankaran commented 1 day ago

@jarthana @stephan-herrmann - FYI - My reading of 15.29 & 14.11.1 says this program should be rejected, but javac 23 compiles it. We don't: case expressions must be constant expressions