8224031: Cannot parse switch expressions after type cast
Correctly categorize parentheses followed by the switch keyword as cast. Reviewed-by: mcimadamore
This commit is contained in:
parent
c39088c391
commit
08193be19c
@ -1655,6 +1655,7 @@ public class JavacParser implements Parser {
|
||||
case DOUBLELITERAL: case CHARLITERAL: case STRINGLITERAL:
|
||||
case TRUE: case FALSE: case NULL:
|
||||
case NEW: case IDENTIFIER: case ASSERT: case ENUM: case UNDERSCORE:
|
||||
case SWITCH:
|
||||
case BYTE: case SHORT: case CHAR: case INT:
|
||||
case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID:
|
||||
return ParensResult.CAST;
|
||||
|
@ -1,4 +1,4 @@
|
||||
ExpressionSwitch.java:39:16: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.expressions)
|
||||
ExpressionSwitch.java:40:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.rules)
|
||||
ExpressionSwitch.java:92:31: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.multiple.case.labels)
|
||||
ExpressionSwitch.java:40:16: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.expressions)
|
||||
ExpressionSwitch.java:41:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.rules)
|
||||
ExpressionSwitch.java:93:31: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.multiple.case.labels)
|
||||
3 errors
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8206986 8222169
|
||||
* @bug 8206986 8222169 8224031
|
||||
* @summary Check expression switch works.
|
||||
* @compile/fail/ref=ExpressionSwitch-old.out -source 9 -Xlint:-options -XDrawDiagnostics ExpressionSwitch.java
|
||||
* @compile --enable-preview -source ${jdk.version} ExpressionSwitch.java
|
||||
@ -33,6 +33,7 @@ public class ExpressionSwitch {
|
||||
assertEquals(convert2("C"), 1);
|
||||
assertEquals(convert2(""), -1);
|
||||
localClass(T.A);
|
||||
assertEquals(castSwitchExpressions(T.A), "A");
|
||||
}
|
||||
|
||||
private String print(T t) {
|
||||
@ -121,6 +122,13 @@ public class ExpressionSwitch {
|
||||
}
|
||||
}
|
||||
|
||||
private String castSwitchExpressions(T t) {
|
||||
return (String) switch (t) {
|
||||
case A -> "A";
|
||||
default -> 1;
|
||||
};
|
||||
}
|
||||
|
||||
private void check(T t, String expected) {
|
||||
String result = print(t);
|
||||
assertEquals(result, expected);
|
||||
|
Loading…
x
Reference in New Issue
Block a user