diff options
author | Manoj Palat | 2020-05-14 07:22:15 +0000 |
---|---|---|
committer | Manoj Palat | 2020-05-14 16:04:40 +0000 |
commit | 50ef901adb0dfc4f68616b8c5ee8bf24bb75c839 (patch) | |
tree | 622c36216bcb72c8245bbafd9a1b0ace24ab2c43 | |
parent | 618da9b0c9caf1158ea6f03901fac160c2cf4b10 (diff) | |
download | eclipse.jdt.core-50ef901adb0dfc4f68616b8c5ee8bf24bb75c839.tar.gz eclipse.jdt.core-50ef901adb0dfc4f68616b8c5ee8bf24bb75c839.tar.xz eclipse.jdt.core-50ef901adb0dfc4f68616b8c5ee8bf24bb75c839.zip |
incorrectly
Change-Id: Ifa8140c622fc404ebadc5b2af7d77270615cd528
2 files changed, 112 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java index 9f4532e8f4..4b46ebc746 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java @@ -4872,4 +4872,112 @@ public class SwitchExpressionsYieldTest extends AbstractRegressionTest { "Return within switch expressions not permitted\n" + "----------\n"); } + public void testBug563147_001() { + runConformTest( + new String[] { + "X.java", + "interface I {\n"+ + " public int apply();\n"+ + "}\n"+ + "public class X { \n"+ + " static public int foo(int a){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " I lambda = () -> { return 0;};\n"+ + " yield lambda.apply();\n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(1));\n"+ + " }\n"+ + "} \n" + }, + "0"); + } + public void testBug563147_002() { + runConformTest( + new String[] { + "X.java", + "interface FI {\n"+ + " public int foo();\n"+ + "}\n"+ + "public class X {\n"+ + " public int field = 0;\n"+ + " public int test() {\n"+ + " var v = switch (field) {\n"+ + " case 0 -> {\n"+ + " yield ((FI ) () -> {\n"+ + " int i = 0;\n"+ + " while (true) {\n"+ + " i++;\n"+ + " if (i == 7) {\n"+ + " break;\n"+ + " }\n"+ + " }\n"+ + " return i;\n"+ + " }); \n"+ + " }\n"+ + " default -> {\n"+ + " yield null;\n"+ + " }\n"+ + " }; \n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " int t = new X().test();\n"+ + " System.out.println(t);\n"+ + "}\n"+ + "}\n" + }, + "0"); + } + public void testBug563147_003() { + this.runNegativeTest( + new String[] { + "X.java", + "interface FI {\n"+ + " public int foo();\n"+ + "}\n"+ + "public class X {\n"+ + " public int field = 0;\n"+ + " public int test() {\n"+ + " var v = switch (field) {\n"+ + " case 0 -> {\n"+ + " yield ((F ) () -> {\n"+ + " int i = 0;\n"+ + " while (true) {\n"+ + " i++;\n"+ + " if (i == 7) {\n"+ + " break;\n"+ + " }\n"+ + " }\n"+ + " return i;\n"+ + " }); \n"+ + " }\n"+ + " default -> {\n"+ + " yield null;\n"+ + " }\n"+ + " }; \n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " int t = new X().test();\n"+ + " System.out.println(t);\n"+ + "}\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " yield ((F ) () -> {\n" + + " ^\n" + + "F cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " yield ((F ) () -> {\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); + } } 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 be79ed528b..6d10ca950e 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 @@ -429,6 +429,10 @@ public class SwitchExpression extends SwitchStatement implements IPolyExpression return true; } @Override + public boolean visit(LambdaExpression lambdaExpression, BlockScope blockScope) { + return false; + } + @Override public boolean visit(LabeledStatement stmt, BlockScope blockScope) { if (stmt.label != null && stmt.label.length != 0) this.labelDecls.add(new String(stmt.label)); |