changeset 56798:321d2ca49a87 patterns-deconstruction

Merging recent changes from the patterns branch into the patterns-deconstruction branch.
author jlahoda
date Mon, 17 Jun 2019 17:21:13 +0200
parents e6e27550e2d5 91e02ad382d2
children 9221f7d08dd6
files test/langtools/tools/javac/patterns/SwitchExpressionWithPatterns.java
diffstat 2 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransSwitches.java	Mon Jun 17 17:14:55 2019 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransSwitches.java	Mon Jun 17 17:21:13 2019 +0200
@@ -160,14 +160,14 @@
                 @Override
                 public void visitYield(JCYield tree) {
                     if (tree.target == switchExpr) {
-                        tree.target = switchStatement;
+                        JCBreak newBreak = make.Break(null);
+                        newBreak.target = switchStatement;
                         JCExpressionStatement assignment =
                                 make.Exec(make.Assign(make.Ident(dollar_switchexpr),
                                                       translate(tree.value))
                                               .setType(dollar_switchexpr.type));
                         result = make.Block(0, List.of(assignment,
-                                                       tree));
-                        tree.value = null;
+                                                       newBreak));
                     } else {
                         result = tree;
                     }
--- a/test/langtools/tools/javac/patterns/SwitchExpressionWithPatterns.java	Mon Jun 17 17:14:55 2019 +0200
+++ b/test/langtools/tools/javac/patterns/SwitchExpressionWithPatterns.java	Mon Jun 17 17:21:13 2019 +0200
@@ -24,7 +24,7 @@
 /*
  * @test
  * @summary Basic test for patterns in switch expression
- * @compile --enable-preview -source 13 SwitchExpressionWithPatterns.java
+ * @compile --enable-preview -source ${jdk.version} SwitchExpressionWithPatterns.java
  * @run main/othervm --enable-preview SwitchExpressionWithPatterns
  */
 
@@ -55,11 +55,11 @@
         int check = 0;
         return switch (in) {
             case 41: check++; //fall-through
-            case Integer i: check++; break check;
-            case Long l, Float f: break 3;
-            case R(0, var j): break 100 + j;
-            case R(var i, var j): break i + j;
-            default: break 4;
+            case Integer i: check++; yield check;
+            case Long l, Float f: yield 3;
+            case R(0, var j): yield 100 + j;
+            case R(var i, var j): yield i + j;
+            default: yield 4;
         };
 
     }
@@ -68,11 +68,11 @@
         int check = 0;
         return switch (in) {
             case 41 -> 2;
-            case Integer j -> { break 1; }
+            case Integer j -> { yield 1; }
             case Long l, Float f -> 3;
             case R(0, var j) -> 100 + j;
             case R(var i, var j) -> i + j;
-            default -> { break 4; }
+            default -> { yield 4; }
         };
     }