changeset 49304:00909878a9f3 switch

Adding test for ambiguous break that has a wrong expression type.
author jlahoda
date Wed, 21 Feb 2018 08:20:31 +0100
parents dd79a2d208a6
children a6b463a66e0c
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out
diffstat 3 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Feb 15 19:10:19 2018 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Feb 21 08:20:31 2018 +0100
@@ -1868,7 +1868,6 @@
                     Pair<JCTree, Error> jumpTarget = findJumpTargetNoError(tree.getTag(), label, env);
 
                     if (jumpTarget.fst != null) {
-                        //TODO: add test - identifier whose type does not match the expected type! (test for unknownExprInfo)
                         JCTree speculative = deferredAttr.attribSpeculative(tree.value, env, unknownExprInfo);
                         if (!speculative.type.hasTag(ERROR)) {
                             log.error(tree.pos(), Errors.BreakAmbiguousTarget(label));
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java	Thu Feb 15 19:10:19 2018 -0500
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java	Wed Feb 21 08:20:31 2018 +0100
@@ -37,6 +37,13 @@
                         break ; //error: missing value
                     case 2:
                         break OUTER; //error: jumping outside of the switch expression
+                    case 3: {
+                        int x = -1;
+                        x: switch (i + j) {
+                            case 0: break x; //error: cannot disambiguate, wrong type as well
+                        }
+                        break "X";
+                    }
                     default: {
                         String x = "X";
                         x: switch (i + j) {
--- a/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out	Thu Feb 15 19:10:19 2018 -0500
+++ b/test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.out	Wed Feb 21 08:20:31 2018 +0100
@@ -1,6 +1,7 @@
 ExpressionSwitchBreaks2.java:37:25: compiler.err.break.missing.value
 ExpressionSwitchBreaks2.java:39:25: compiler.err.break.outside.switch.expression
 ExpressionSwitchBreaks2.java:43:37: compiler.err.break.ambiguous.target: x
-ExpressionSwitchBreaks2.java:49:17: compiler.err.break.complex.value.no.switch.expression
-ExpressionSwitchBreaks2.java:49:29: compiler.err.cant.resolve.location: kindname.variable, undef, , , (compiler.misc.location: kindname.class, ExpressionSwitchBreaks2, null)
-5 errors
+ExpressionSwitchBreaks2.java:50:37: compiler.err.break.ambiguous.target: x
+ExpressionSwitchBreaks2.java:56:17: compiler.err.break.complex.value.no.switch.expression
+ExpressionSwitchBreaks2.java:56:29: compiler.err.cant.resolve.location: kindname.variable, undef, , , (compiler.misc.location: kindname.class, ExpressionSwitchBreaks2, null)
+6 errors