8269141: Switch statement containing pattern case label element gets in the loop during execution
Reviewed-by: vromero
This commit is contained in:
parent
6b64a7956c
commit
c3c918928c
src/jdk.compiler/share/classes/com/sun/tools/javac/jvm
test/langtools/tools/javac/patterns
@ -1375,8 +1375,7 @@ public class Gen extends JCTree.Visitor {
|
||||
|
||||
if (switchEnv.info.cont != null) {
|
||||
Assert.check(patternSwitch);
|
||||
code.resolve(switchEnv.info.cont);
|
||||
code.resolve(code.branch(goto_), switchStart);
|
||||
code.resolve(switchEnv.info.cont, switchStart);
|
||||
}
|
||||
|
||||
// Resolve all breaks.
|
||||
|
@ -27,7 +27,7 @@ import java.util.function.Function;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8262891 8268333
|
||||
* @bug 8262891 8268333 8268896
|
||||
* @summary Check behavior of pattern switches.
|
||||
* @compile --enable-preview -source ${jdk.version} Switches.java
|
||||
* @run main/othervm --enable-preview Switches
|
||||
@ -60,6 +60,8 @@ public class Switches {
|
||||
runEnumTest(this::testIntegerWithGuardsExpression1);
|
||||
runStringWithConstant(this::testStringWithConstant);
|
||||
runStringWithConstant(this::testStringWithConstantExpression);
|
||||
runFallThrough(this::testFallThroughStatement);
|
||||
runFallThrough(this::testFallThroughExpression);
|
||||
npeTest(this::npeTestStatement);
|
||||
npeTest(this::npeTestExpression);
|
||||
exhaustiveStatementSane("");
|
||||
@ -104,6 +106,10 @@ public class Switches {
|
||||
assertEquals(-1, mapper.apply(null));
|
||||
}
|
||||
|
||||
void runFallThrough(Function<Integer, Integer> mapper) {
|
||||
assertEquals(2, mapper.apply(1));
|
||||
}
|
||||
|
||||
void npeTest(Consumer<I> testCase) {
|
||||
try {
|
||||
testCase.accept(null);
|
||||
@ -309,6 +315,31 @@ public class Switches {
|
||||
};
|
||||
}
|
||||
|
||||
Integer testFallThroughStatement(Integer i) {
|
||||
int r = 0;
|
||||
|
||||
switch (i) {
|
||||
case Integer o && o != null:
|
||||
r = 1;
|
||||
default:
|
||||
r = 2;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
Integer testFallThroughExpression(Integer i) {
|
||||
int r = switch (i) {
|
||||
case Integer o && o != null:
|
||||
r = 1;
|
||||
default:
|
||||
r = 2;
|
||||
yield r;
|
||||
};
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void npeTestStatement(I i) {
|
||||
switch (i) {
|
||||
case A a -> {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user