changeset 52898:37bbcd1f1f50 patterns

Fixing String switch expression bug as reported by forax on amber-dev.
author jlahoda
date Wed, 17 Oct 2018 13:56:45 +0200
parents 82d785fc4c29
children eb75b11c373d 2cb2cae03443
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransSwitches.java test/langtools/tools/javac/switchexpr/ExpressionSwitch-old.out test/langtools/tools/javac/switchexpr/ExpressionSwitch.java
diffstat 3 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransSwitches.java	Mon Oct 08 20:25:06 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransSwitches.java	Wed Oct 17 13:56:45 2018 +0200
@@ -207,7 +207,7 @@
                     }
                 }
             }.translate(c.stats));
-            JCCase res = make.Case(c.caseKind, c.pats, statements.toList(), null);
+            JCCase res = make.Case(JCCase.STATEMENT, c.pats, statements.toList(), null);
             res.completesNormally = c.completesNormally;
             return res;
         }
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitch-old.out	Mon Oct 08 20:25:06 2018 +0200
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitch-old.out	Wed Oct 17 13:56:45 2018 +0200
@@ -1,3 +1,4 @@
-ExpressionSwitch.java:30:16: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.expressions)
-ExpressionSwitch.java:31:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.rules)
-2 errors
+ExpressionSwitch.java:34:16: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.expressions)
+ExpressionSwitch.java:35:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.switch.rules)
+ExpressionSwitch.java:85:21: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.multiple.case.labels)
+3 errors
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitch.java	Mon Oct 08 20:25:06 2018 +0200
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitch.java	Wed Oct 17 13:56:45 2018 +0200
@@ -23,6 +23,10 @@
         assertEquals(scopesIsolated(T.B), "B");
         assertEquals(lambdas1(T.B).get(), "B");
         assertEquals(lambdas2(T.B).get(), "B");
+        assertEquals(stringSwitchExpr("A"), "0");
+        assertEquals(stringSwitchExpr("B"), "0");
+        assertEquals(stringSwitchExpr("C"), "1");
+        assertEquals(stringSwitchExpr("X"), "D");
         localClass(T.A);
     }
 
@@ -76,6 +80,14 @@
         };
     }
 
+    private String stringSwitchExpr(String str) {
+        return switch (str) {
+            case "A", "B" -> { break "0"; }
+            case "C" -> "1";
+            default -> "D";
+        };
+    }
+
     private void localClass(T t) {
         String good = "good";
         class L {