Reported here:
https://mail.openjdk.org/pipermail/compiler-dev/2025-January/029309.html
Consider code like:
---
public class X {
record Point (int x, int y) {}
static void foo(Object o) {
switch (o) {
case Integer _, Point(int x, int _), String _ :
System.out.println("Integer");
default:
System.out.println("Object");
}
}
public static void main(String [] args) {
foo("");
}
}
---
javac will compile this code, even though JLS 14.11.1 specifies a compile-time error should be reported:
It is a compile-time error for a case label to have more than one case pattern and declare any pattern variables (other than those declared by a guard associated with the case label).
https://mail.openjdk.org/pipermail/compiler-dev/2025-January/029309.html
Consider code like:
---
public class X {
record Point (int x, int y) {}
static void foo(Object o) {
switch (o) {
case Integer _, Point(int x, int _), String _ :
System.out.println("Integer");
default:
System.out.println("Object");
}
}
public static void main(String [] args) {
foo("");
}
}
---
javac will compile this code, even though JLS 14.11.1 specifies a compile-time error should be reported:
It is a compile-time error for a case label to have more than one case pattern and declare any pattern variables (other than those declared by a guard associated with the case label).
- csr for
-
JDK-8348933 Check for case label validity are misbehaving when binding patterns with unnamed bindings are present
-
- Draft
-