Skip to content
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

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -4774,7 +4774,7 @@ boolean hasBindings(JCTree p) {
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);
20 changes: 19 additions & 1 deletion test/langtools/tools/javac/patterns/SwitchErrors.java
Original file line number Diff line number Diff line change
@@ -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 @@ void test8269301bb(Integer i) {
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:
}
}
}
4 changes: 3 additions & 1 deletion test/langtools/tools/javac/patterns/SwitchErrors.out
Original file line number Diff line number Diff line change
@@ -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