Bug 545715 - [12] Assignment analysis doesn't work in switch statement
with ->
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 78b1202..e4e6e8e 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 @@
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 a5b07d0..a68fa56 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 @@
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)