Skip to content

Commit

Permalink
8321582: yield <primitive-type>.class not parsed correctly.
Browse files Browse the repository at this point in the history
Backport-of: ce8399fd6071766114f5f201b6e44a7abdba9f5a
  • Loading branch information
shipilev committed Jan 15, 2024
1 parent d92ff7c commit e08eb0e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Expand Up @@ -2854,6 +2854,7 @@ List<JCStatement> blockStatement() {
case INTLITERAL: case LONGLITERAL: case FLOATLITERAL: case DOUBLELITERAL:
case NULL: case IDENTIFIER: case TRUE: case FALSE:
case NEW: case SWITCH: case THIS: case SUPER:
case BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, VOID, BOOLEAN:
isYieldStatement = true;
break;
case PLUSPLUS: case SUBSUB:
Expand Down
29 changes: 27 additions & 2 deletions test/langtools/tools/javac/switchexpr/ExpressionSwitch.java
@@ -1,12 +1,12 @@
/*
* @test /nodynamiccopyright/
* @bug 8206986 8222169 8224031 8240964 8267119 8268670
* @bug 8206986 8222169 8224031 8240964 8267119 8268670 8321582
* @summary Check expression switch works.
* @compile/fail/ref=ExpressionSwitch-old.out --release 9 -XDrawDiagnostics ExpressionSwitch.java
* @compile ExpressionSwitch.java
* @run main ExpressionSwitch
*/

// * @compile/fail/ref=ExpressionSwitch-old.out --release 9 -XDrawDiagnostics ExpressionSwitch.java
import java.util.Objects;
import java.util.function.Supplier;

Expand Down Expand Up @@ -35,6 +35,16 @@ private void run() {
localClass(T.A);
assertEquals(castSwitchExpressions(T.A), "A");
testTypeInference(true, 0);
assertEquals(yieldPrimitiveDotClass("byte"), byte.class);
assertEquals(yieldPrimitiveDotClass("char"), char.class);
assertEquals(yieldPrimitiveDotClass("short"), short.class);
assertEquals(yieldPrimitiveDotClass("int"), int.class);
assertEquals(yieldPrimitiveDotClass("long"), long.class);
assertEquals(yieldPrimitiveDotClass("float"), float.class);
assertEquals(yieldPrimitiveDotClass("double"), double.class);
assertEquals(yieldPrimitiveDotClass("void"), void.class);
assertEquals(yieldPrimitiveDotClass("boolean"), boolean.class);
assertEquals(yieldPrimitiveDotClass("other"), null);
}

private String print(T t) {
Expand Down Expand Up @@ -140,6 +150,21 @@ private boolean yieldUnaryNotOperator(String s, boolean b) {
};
}

private Class<?> yieldPrimitiveDotClass(String s) {
return switch (s) {
case "byte": yield byte.class;
case "char": yield char.class;
case "short": yield short.class;
case "int": yield int.class;
case "long": yield long.class;
case "float": yield float.class;
case "double": yield double.class;
case "void": yield void.class;
case "boolean": yield boolean.class;
default: yield null;
};
}

private void localClass(T t) {
String good = "good";
class L {
Expand Down

1 comment on commit e08eb0e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.