changeset 2480:340148a26acf

8042759: Lambda returning implicitly-typed lambdas considered pertinent to applicability Reviewed-by: mcimadamore
author vromero
date Thu, 19 Jun 2014 23:52:33 +0100
parents 8085359d9444
children 9b187f24c709
files src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.java test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.out
diffstat 3 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Jun 19 22:06:29 2014 +0200
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Jun 19 23:52:33 2014 +0100
@@ -953,7 +953,7 @@
 
         LambdaReturnScanner() {
             super(EnumSet.of(BLOCK, CASE, CATCH, DOLOOP, FOREACHLOOP,
-                    FORLOOP, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP));
+                    FORLOOP, IF, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP));
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.java	Thu Jun 19 23:52:33 2014 +0100
@@ -0,0 +1,33 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8042759
+ * @summary Lambda returning implicitly-typed lambdas considered pertinent to applicability
+ * @compile/fail/ref=ImplicitLambdaConsideredForApplicabilityTest.out -XDrawDiagnostics ImplicitLambdaConsideredForApplicabilityTest.java
+ */
+
+abstract class ImplicitLambdaConsideredForApplicabilityTest {
+    interface A {
+        B m(int a, int b);
+    }
+
+    interface C {
+        String m(int a, int b);
+    }
+
+    interface B {
+        int m(int c);
+    }
+
+    abstract void foo(A a);
+
+    abstract void foo(C c);
+
+    void bar() {
+        foo((int a, int b) -> {
+            if(a < b)
+                return c -> 0;
+            else
+                return c -> 0;
+        });
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.out	Thu Jun 19 23:52:33 2014 +0100
@@ -0,0 +1,2 @@
+ImplicitLambdaConsideredForApplicabilityTest.java:26:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(ImplicitLambdaConsideredForApplicabilityTest.A), ImplicitLambdaConsideredForApplicabilityTest, kindname.method, foo(ImplicitLambdaConsideredForApplicabilityTest.C), ImplicitLambdaConsideredForApplicabilityTest
+1 error