From bc14b2cd549a482f648d983b3db10e6125179239 Mon Sep 17 00:00:00 2001 From: Olivier Thomann Date: Sat, 9 Feb 2019 03:13:56 +0530 Subject: Bug 544254 [12][codegen] Switch Expressions - Inconsistent stackmap frames at branch target error and Bug 544253 - [12][codegen] Switch Expressions - Multiple codegen errors Change-Id: I7211d9737c7e26365a7250c68e725a9cce15e072 --- .../compiler/regression/SwitchExpressionTest.java | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) (limited to 'org.eclipse.jdt.core.tests.compiler/src') 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 d50878833f..cfabad7ae0 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 @@ -1713,4 +1713,101 @@ public class SwitchExpressionTest extends AbstractRegressionTest { "missing enum constant(s) in switch expression as all enum constants are required in case statements if there is no default case.\n" + "----------\n"); } + public void testBug544253() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(int i ) {\n" + + " boolean b = switch (i) {\n" + + " case 0 -> i == 1;\n" + + " default -> true;\n" + + " };\n" + + " System.out.println( b ? \" true\" : \"false\");\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " new X().foo(0);\n" + + " }\n" + + "}" + }, + "false", + null, + new String[] {"--enable-preview"}); + } + public void testBug544254() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " try {\n" + + " int i = switch (s) {\n" + + " case \"hello\" -> 0;\n" + + " default -> 2;\n" + + " };\n" + + " } finally {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(\"hello\");\n" + + " }\n" + + "}" + }, + "hello", + null, + new String[] {"--enable-preview"}); + } + public void testBug544254_2() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " try {\n" + + " int i = switch (s) {\n" + + " case \"hello\" -> 0;\n" + + " default -> 2;\n" + + " };\n" + + " } finally {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(\"hello\");\n" + + " }\n" + + "}" + }, + "hello", + customOptions, + new String[] {"--enable-preview"}); + } + public void testBug544254_3() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " try {\n" + + " long l = switch (s) {\n" + + " case \"hello\" -> 0;\n" + + " default -> 2;\n" + + " };\n" + + " } finally {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(\"hello\");\n" + + " }\n" + + "}" + }, + "hello", + customOptions, + new String[] {"--enable-preview"}); + } } \ No newline at end of file -- cgit v1.2.3