diff options
author | Manoj Palat | 2019-04-17 10:00:09 +0000 |
---|---|---|
committer | Manoj Palat | 2019-04-17 10:00:09 +0000 |
commit | 613881dc780425fd54173639c561922b9fcc5ff3 (patch) | |
tree | 9998b22ccff85683eb272a2430fcb12ea95e51ad | |
parent | bd2710396dddf798a364e0bd043e4dbe8ad7156c (diff) | |
download | eclipse.jdt.core-I20190419-1800.tar.gz eclipse.jdt.core-I20190419-1800.tar.xz eclipse.jdt.core-I20190419-1800.zip |
Bug 545715 - [12] Assignment analysis doesn't work in switch statementI20190420-1800I20190419-1800I20190418-1800I20190417-1800
with ->
Change-Id: I1e8c81771aa6ccb0462a55e8ad662c38cd087b29
3 files changed, 22 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java index 63fa7e928d..e850cdcb17 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java @@ -41,7 +41,7 @@ public NullAnnotationTest(String name) { // Static initializer to specify tests subset using TESTS_* static variables // All specified tests which do not belong to the class are skipped... static { -// TESTS_NAMES = new String[] { "test_default_nullness_003a" }; +// TESTS_NAMES = new String[] { "testBug545715" }; // TESTS_NUMBERS = new int[] { 561 }; // TESTS_RANGE = new int[] { 1, 2049 }; } @@ -10583,4 +10583,23 @@ public void testBug542707_006() { "----------\n"; runner.runNegativeTest(); } +public void testBug545715() { + if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression + Map<String, String> customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "X.java", + "public class X {\n"+ + " void f() {\n"+ + " loop: while(true) {\n"+ + " break loop;\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + customOptions, + ""); +} } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java index 1fdedea27e..e39937479f 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java @@ -2362,7 +2362,7 @@ public class SwitchExpressionTest extends AbstractRegressionTest { new String[] { "--enable-preview"}, options); } - public void _testBug545915_01() { + public void testBug545715_01() { runConformTest( new String[] { "X.java", diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java index a5b07d0bb2..ada2ae6b26 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java @@ -50,7 +50,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl return flowInfo; // pretend it did not break since no actual target } - if (this.switchExpression != null && this.expression != null) { + if ((this.isImplicit || this.switchExpression != null) && this.expression != null) { flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo); this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo); if (flowInfo.reachMode() == FlowInfo.REACHABLE && currentScope.compilerOptions().isAnnotationBasedNullAnalysisEnabled) |