changeset 60491:4eaf6922273a

8240964: Compilation error thrown when long literal used with yield Summary: Ensuring yield followed by a long literal is recognized as a yield statement. Reviewed-by: mcimadamore
author jlahoda
date Mon, 16 Mar 2020 13:06:35 +0100
parents 59b5bd9a7168
children 80eaef8e3e60
files src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java test/langtools/tools/javac/switchexpr/ExpressionSwitch.java
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Mar 16 02:16:49 2020 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Mar 16 13:06:35 2020 +0100
@@ -2582,7 +2582,7 @@
                 boolean isYieldStatement;
                 switch (next.kind) {
                     case PLUS: case SUB: case STRINGLITERAL: case CHARLITERAL:
-                    case INTLITERAL: case FLOATLITERAL: case DOUBLELITERAL:
+                    case INTLITERAL: case LONGLITERAL: case FLOATLITERAL: case DOUBLELITERAL:
                     case NULL: case IDENTIFIER: case TRUE: case FALSE:
                     case NEW: case SWITCH: case THIS: case SUPER:
                         isYieldStatement = true;
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitch.java	Mon Mar 16 02:16:49 2020 -0400
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitch.java	Mon Mar 16 13:06:35 2020 +0100
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 8206986 8222169 8224031
+ * @bug 8206986 8222169 8224031 8240964
  * @summary Check expression switch works.
  * @compile/fail/ref=ExpressionSwitch-old.out -source 9 -Xlint:-options -XDrawDiagnostics ExpressionSwitch.java
  * @compile ExpressionSwitch.java
@@ -104,6 +104,21 @@
         };
     }
 
+    private Object yieldDisambiguationLiterals(String s) {
+        return switch (s) {
+            case "a": yield 0;
+            case "b": yield 0L;
+            case "c": yield 0.0f;
+            case "d": yield 0.0d;
+            case "e": yield true;
+            case "f": yield false;
+            case "g": yield '0';
+            case "h": yield "";
+            case "i": yield null;
+            default: yield 0;
+        };
+    }
+
     private void localClass(T t) {
         String good = "good";
         class L {