8348928: Check for case label validity are misbehaving when binding patterns with unnamed bindings are present

Reviewed-by: asotona, abimpoudis, vromero
This commit is contained in:
Jan Lahoda 2025-04-24 06:58:37 +00:00
parent 188c236071
commit 7bfbb9a515
3 changed files with 23 additions and 3 deletions

View File

@ -4777,7 +4777,7 @@ public class Check {
new TreeScanner() {
@Override
public void visitBindingPattern(JCBindingPattern tree) {
bindings[0] = !tree.var.sym.isUnnamedVariable();
bindings[0] |= !tree.var.sym.isUnnamedVariable();
super.visitBindingPattern(tree);
}
}.scan(p);

View File

@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 8262891 8269146 8269113
* @bug 8262891 8269146 8269113 8348928
* @summary Verify errors related to pattern switches.
* @compile/fail/ref=SwitchErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW SwitchErrors.java
*/
@ -307,4 +307,22 @@ public class SwitchErrors {
break;
}
}
void testPatternWithoutBindingCantOverridePatternWithBinding8348928a(Object o) {
record R(int i, String s) {}
switch (o) {
case Integer _, R(int x, String _) -> {}
default -> {}
}
}
void testPatternWithoutBindingCantOverridePatternWithBinding8348928b(Object o) {
record R(int i, String s) {}
switch (o) {
case Integer _:
case R(int x, String _):
break;
default:
}
}
}

View File

@ -57,6 +57,8 @@ SwitchErrors.java:276:49: compiler.err.cant.resolve.location.args: kindname.meth
SwitchErrors.java:278:55: compiler.err.cant.resolve.location.args: kindname.method, length, , , (compiler.misc.location: kindname.class, java.lang.Object, null)
SwitchErrors.java:284:26: compiler.err.pattern.type.cannot.infer
SwitchErrors.java:299:21: compiler.err.invalid.case.label.combination
SwitchErrors.java:314:29: compiler.err.flows.through.from.pattern
SwitchErrors.java:323:18: compiler.err.flows.through.to.pattern
SwitchErrors.java:10:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:16:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:22:9: compiler.err.not.exhaustive.statement
@ -69,4 +71,4 @@ SwitchErrors.java:98:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:105:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:153:9: compiler.err.not.exhaustive.statement
SwitchErrors.java:226:9: compiler.err.not.exhaustive.statement
71 errors
73 errors