Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2019-04-08 02:43:20 -0400
committerManoj Palat2019-04-08 02:43:20 -0400
commit9e12782ba2ffa4c85cbfa25013efa0ede16bdd90 (patch)
tree3b79ac4acae23e12a6725251f3b81299691267b6
parentf2d78dd3aac45bbe38e89f45932a53aa8b28ca2a (diff)
downloadeclipse.jdt.core-9e12782ba2ffa4c85cbfa25013efa0ede16bdd90.tar.gz
eclipse.jdt.core-9e12782ba2ffa4c85cbfa25013efa0ede16bdd90.tar.xz
eclipse.jdt.core-9e12782ba2ffa4c85cbfa25013efa0ede16bdd90.zip
Bug 545715 - [12] Assignment analysis doesn't work in switch statementI20190408-0600
with ->
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionTest.java23
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java2
2 files changed, 24 insertions, 1 deletions
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 78b120276e..e4e6e8ed0b 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,4 +2362,27 @@ public class SwitchExpressionTest extends AbstractRegressionTest {
new String[] { "--enable-preview"},
options);
}
+ public void testBug545915_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "enum X {\n"+
+ " A, B; \n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " public static void main(String[] args) {\n"+
+ " X myEnum = X.A;\n"+
+ " int o;\n"+
+ " switch(myEnum) {\n"+
+ " case A -> o = 5;\n"+
+ " case B -> o = 10;\n"+
+ " default -> o = 0;\n"+
+ " }\n"+
+ " System.out.println(o);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "5",
+ null,
+ new String[] {"--enable-preview"});
+ }
}
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..a68fa56e40 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.expression != null) {
flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo);
this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo);
if (flowInfo.reachMode() == FlowInfo.REACHABLE && currentScope.compilerOptions().isAnnotationBasedNullAnalysisEnabled)

Back to the top