-
Bug
-
Resolution: Fixed
-
P3
-
21
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8314681 | 21.0.1 | Angelos Bimpoudis | P3 | Resolved | Fixed | b08 |
Code:
package com.example;
public class Test {
enum X {A, B}
void test(Object obj) {
switch (obj) {
case X.A, Integer _ -> System.out.println("A or Integer");
case String _, X.B -> System.out.println("B or String");
default -> System.out.println("other");
}
}
public static void main(String[] args) {
new Test().test("ddd");
}
}
Compile with --enable-preview
Expected: either successful compilation or two compilation errors in both case lines. Actual: one compilation error:
com\example\Test.java:8:15
java: <identifier> expected
Java parses `case String _, X.B` (when pattern goes first) but does not parse `case X.A, Integer _` when enum constant goes first. It should either accept or reject both. According to current spec draft, it should reject both, but probably it's better to rectify the spec draft.
package com.example;
public class Test {
enum X {A, B}
void test(Object obj) {
switch (obj) {
case X.A, Integer _ -> System.out.println("A or Integer");
case String _, X.B -> System.out.println("B or String");
default -> System.out.println("other");
}
}
public static void main(String[] args) {
new Test().test("ddd");
}
}
Compile with --enable-preview
Expected: either successful compilation or two compilation errors in both case lines. Actual: one compilation error:
com\example\Test.java:8:15
java: <identifier> expected
Java parses `case String _, X.B` (when pattern goes first) but does not parse `case X.A, Integer _` when enum constant goes first. It should either accept or reject both. According to current spec draft, it should reject both, but probably it's better to rectify the spec draft.
- backported by
-
JDK-8314681 Case enumConstant, pattern compilation fails
-
- Resolved
-