changeset 55896:07493e0a0be6 switch2

Adjusting errors for break-with.
author jlahoda
date Wed, 24 Apr 2019 14:31:02 +0200
parents 427b3a55b5d4
children 850fab702c3d
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties test/langtools/tools/javac/diags/examples/BreakAmbiguousTarget.java test/langtools/tools/javac/diags/examples/BreakComplexValueNoSwitchExpression.java test/langtools/tools/javac/diags/examples/BreakExprNotImmediate.java test/langtools/tools/javac/diags/examples/BreakMissingValue.java test/langtools/tools/javac/diags/examples/SwitchExpressions.java
diffstat 7 files changed, 4 insertions(+), 179 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Apr 24 14:09:45 2019 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Apr 24 14:31:02 2019 +0200
@@ -1876,18 +1876,7 @@
                           diags.fragment(Fragments.UnexpectedRetVal));
             }
             attribTree(tree.value, env, env.info.breakResult);
-            JCTree immediateTarget = findJumpTarget(tree.pos(), tree.getTag(), names.empty, env);
-            if (immediateTarget.getTag() != SWITCH_EXPRESSION) {
-                log.error(tree.pos(), Errors.BreakExprNotImmediate(immediateTarget.getTag()));
-                Env<AttrContext> env1 = env;
-                while (env1 != null && env1.tree.getTag() != SWITCH_EXPRESSION) {
-                    env1 = env1.next;
-                }
-                Assert.checkNonNull(env1);
-                tree.target = env1.tree;
-            } else {
-                tree.target = immediateTarget;
-            }
+            tree.target = findJumpTarget(tree.pos(), tree.getTag(), names.empty, env);
         } else {
             log.error(tree.pos(), Errors.BreakComplexValueNoSwitchExpression);
             attribTree(tree.value, env, unknownExprInfo);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed Apr 24 14:09:45 2019 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed Apr 24 14:31:02 2019 +0200
@@ -188,9 +188,6 @@
 compiler.err.break.outside.switch.loop=\
     break outside switch or loop
 
-compiler.err.break.missing.value=\
-    missing break value
-
 compiler.err.break.outside.switch.expression=\
     break outside of enclosing switch expression
 
@@ -208,17 +205,8 @@
     switch expression completes without providing a value\n\
     (switch expressions must either provide a value or throw for all possible input values)
 
-# 0: name
-compiler.err.break.ambiguous.target=\
-    ambiguous reference to ''{0}''\n\
-    (''{0}'' is both a label and an expression)
-
-# 0: tree tag
-compiler.err.break.expr.not.immediate=\
-    value break not supported in ''{0}''
-
 compiler.err.break.complex.value.no.switch.expression=\
-    unexpected value break
+    break-with outside of switch expression
 
 compiler.err.switch.expression.empty=\
     switch expression does not have any case clauses
@@ -2638,22 +2626,6 @@
 compiler.misc.kindname.instance.init=\
     instance initializer
 
-# the following are names of tree kinds:
-compiler.misc.tree.tag.forloop=\
-    for
-
-compiler.misc.tree.tag.foreachloop=\
-    for
-
-compiler.misc.tree.tag.whileloop=\
-    while
-
-compiler.misc.tree.tag.doloop=\
-    do
-
-compiler.misc.tree.tag.switch=\
-    switch
-
 #####
 
 compiler.misc.no.args=\
--- a/test/langtools/tools/javac/diags/examples/BreakAmbiguousTarget.java	Wed Apr 24 14:09:45 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.break.ambiguous.target
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
-
-class BreakAmbiguousTarget {
-    void m(int i, int j) {
-        j: print(switch (i) {
-            default: break j;
-        });
-    }
-    void print(int i) { }
-}
--- a/test/langtools/tools/javac/diags/examples/BreakComplexValueNoSwitchExpression.java	Wed Apr 24 14:09:45 2019 +0200
+++ b/test/langtools/tools/javac/diags/examples/BreakComplexValueNoSwitchExpression.java	Wed Apr 24 14:31:02 2019 +0200
@@ -26,7 +26,7 @@
 class BreakComplexValueNoSwitchExpressions {
     void t() {
         while (true) {
-            break 1 + 1;
+            break-with 1 + 1;
         }
     }
 }
--- a/test/langtools/tools/javac/diags/examples/BreakExprNotImmediate.java	Wed Apr 24 14:09:45 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.break.expr.not.immediate
-// key: compiler.misc.tree.tag.doloop
-// key: compiler.misc.tree.tag.foreachloop
-// key: compiler.misc.tree.tag.forloop
-// key: compiler.misc.tree.tag.switch
-// key: compiler.misc.tree.tag.whileloop
-// key: compiler.note.note
-// key: compiler.err.error
-// key: compiler.misc.count.error.plural
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// key: compiler.note.note
-// options: --enable-preview -source ${jdk.version}
-// run: backdoor
-
-class BreakExprNotImmediate {
-    int t(int i) {
-        return switch (i) {
-            case 0:
-                for (; ;) {
-                    break 1 + 1;
-                }
-            case 1:
-                for (String s : new String[0]) {
-                    break 1 + 1;
-                }
-            case 2:
-                while (true) {
-                    break 1 + 1;
-                }
-            case 3:
-                do {
-                    break 1 + 1;
-                } while (true);
-            case 4:
-                switch (i) {
-                    default: break 1 + 1;
-                }
-                break 0;
-        };
-    }
-}
--- a/test/langtools/tools/javac/diags/examples/BreakMissingValue.java	Wed Apr 24 14:09:45 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.break.missing.value
-// key: compiler.note.preview.filename
-// key: compiler.note.preview.recompile
-// options: --enable-preview -source ${jdk.version}
-
-class BreakMissingValue {
-    int t(int i) {
-        return switch (i) {
-            default: break;
-        };
-    }
-}
--- a/test/langtools/tools/javac/diags/examples/SwitchExpressions.java	Wed Apr 24 14:09:45 2019 +0200
+++ b/test/langtools/tools/javac/diags/examples/SwitchExpressions.java	Wed Apr 24 14:31:02 2019 +0200
@@ -28,7 +28,7 @@
 class SwitchExpressions {
     int m(int i) {
         return switch (i) {
-            default: break -1;
+            default: break-with -1;
         };
     }
 }