diff options
2 files changed, 109 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 024a09027e..0e09b494d6 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 @@ -1968,4 +1968,109 @@ public class SwitchExpressionTest extends AbstractRegressionTest { null, new String[] {"--enable-preview"}); } + public void testBug544458() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: i = 10; break true;\n" + + " default: break false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(0));\n" + + " }\n" + + "}" + }, + "1", + null, + new String[] {"--enable-preview"}); + } + public void testBug544458_2() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: i++; break true;\n" + + " default: break false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0", + null, + new String[] {"--enable-preview"}); + } + public void testBug544458_3() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: i+= 10; break true;\n" + + " default: break false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0", + null, + new String[] {"--enable-preview"}); + } + public void testBug544458_4() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: switch(i) {case 4: break;}; break true;\n" + + " default: break false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0", + null, + new String[] {"--enable-preview"}); + } + public void testBug544458_5() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: foo(5); break true;\n" + + " default: break false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0", + null, + new String[] {"--enable-preview"}); + } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java index 2342beeb9e..e5ad0a350f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java @@ -206,7 +206,10 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression } @Override protected void statementGenerateCode(BlockScope currentScope, CodeStream codeStream, Statement statement) { - if (!(statement instanceof Expression)) { + if (!(statement instanceof Expression) + || statement instanceof Assignment + || statement instanceof MessageSend + || (statement instanceof SwitchStatement && !(statement instanceof SwitchExpression))) { super.statementGenerateCode(currentScope, codeStream, statement); return; } |