8314632: Intra-case dominance check fails in the presence of a guard
Reviewed-by: vromero
This commit is contained in:
parent
b408a82f9b
commit
81f8c57e4a
@ -4712,7 +4712,7 @@ public class Check {
|
|||||||
TreeInfo.unguardedCase(testCase);
|
TreeInfo.unguardedCase(testCase);
|
||||||
} else if (label instanceof JCPatternCaseLabel patternCL &&
|
} else if (label instanceof JCPatternCaseLabel patternCL &&
|
||||||
testCaseLabel instanceof JCPatternCaseLabel testPatternCaseLabel &&
|
testCaseLabel instanceof JCPatternCaseLabel testPatternCaseLabel &&
|
||||||
TreeInfo.unguardedCase(testCase)) {
|
(testCase.equals(c) || TreeInfo.unguardedCase(testCase))) {
|
||||||
dominated = patternDominated(testPatternCaseLabel.pat,
|
dominated = patternDominated(testPatternCaseLabel.pat,
|
||||||
patternCL.pat);
|
patternCL.pat);
|
||||||
}
|
}
|
||||||
|
40
test/langtools/tools/javac/patterns/T8314632.java
Normal file
40
test/langtools/tools/javac/patterns/T8314632.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* @test /nodynamiccopyright/
|
||||||
|
* @bug 8314632
|
||||||
|
* @summary Intra-case dominance check fails in the presence of a guard
|
||||||
|
* @enablePreview
|
||||||
|
* @compile/fail/ref=T8314632.out -XDrawDiagnostics T8314632.java
|
||||||
|
*/
|
||||||
|
public class T8314632 {
|
||||||
|
void test1(Object obj) {
|
||||||
|
switch (obj) {
|
||||||
|
case Float _ -> {}
|
||||||
|
case Integer _, CharSequence _, String _ when obj.hashCode() > 0 -> { } // error
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2(Object obj) {
|
||||||
|
switch (obj) {
|
||||||
|
case Float _ -> {}
|
||||||
|
case Integer _, CharSequence _, String _ -> { }
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + obj); // error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test3(Object obj) {
|
||||||
|
switch (obj) {
|
||||||
|
case Float _, CharSequence _ when obj.hashCode() > 0 -> { } // OK
|
||||||
|
case Integer _, String _ when obj.hashCode() > 0 -> { } // OK, since the previous case is guarded
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test4(Object obj) {
|
||||||
|
switch (obj) {
|
||||||
|
case Float _, CharSequence _ -> { } // OK
|
||||||
|
case Integer _, String _ when obj.hashCode() > 0 -> { } // error, since the previous case is unguarded
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
test/langtools/tools/javac/patterns/T8314632.out
Normal file
6
test/langtools/tools/javac/patterns/T8314632.out
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
T8314632.java:12:45: compiler.err.pattern.dominated
|
||||||
|
T8314632.java:20:45: compiler.err.pattern.dominated
|
||||||
|
T8314632.java:36:29: compiler.err.pattern.dominated
|
||||||
|
- compiler.note.preview.filename: T8314632.java, DEFAULT
|
||||||
|
- compiler.note.preview.recompile
|
||||||
|
3 errors
|
Loading…
Reference in New Issue
Block a user