changeset 2251:ef024c4b4c97

8016177: structural most specific and stuckness 8016178: Order of unsticking functional expressions Iron out most specific issues in nested generic method calls.
author mcimadamore
date Thu, 22 Aug 2013 11:48:49 +0100
parents e13d3a6dfaa6
children 373187acfa45
files src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java src/share/classes/com/sun/tools/javac/comp/Resolve.java test/tools/javac/lambda/8016177/T8016177c.java test/tools/javac/lambda/8016177/T8016177c.out test/tools/javac/lambda/8016177/T8016177g.java test/tools/javac/lambda/8016177/T8016177g.out
diffstat 6 files changed, 53 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Tue Aug 20 18:13:09 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Aug 22 11:48:49 2013 +0100
@@ -475,9 +475,13 @@
                     }
                 }
                 if (!progress) {
-                    if (mode == AttrMode.SPECULATIVE) {
-                        //unsticking does not take place during overload
-                        break;
+                    DeferredAttrContext dac = this;
+                    while (dac != emptyDeferredAttrContext) {
+                        if (dac.mode == AttrMode.SPECULATIVE) {
+                            //unsticking does not take place during overload
+                            break;
+                        }
+                        dac = dac.parent;
                     }
                     //remove all variables that have already been instantiated
                     //from the list of stuck variables
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Aug 20 18:13:09 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Aug 22 11:48:49 2013 +0100
@@ -1061,7 +1061,8 @@
                             DeferredType dt = (DeferredType) actual;
                             DeferredType.SpeculativeCache.Entry e = dt.speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase);
                             return (e == null || e.speculativeTree == deferredAttr.stuckTree)
-                                    ? false : mostSpecific(found, req, e.speculativeTree, warn);
+                                    ? super.compatible(found, req, warn) :
+                                      mostSpecific(found, req, e.speculativeTree, warn);
                         default:
                             return standaloneMostSpecific(found, req, actual, warn);
                     }
--- a/test/tools/javac/lambda/8016177/T8016177c.java	Tue Aug 20 18:13:09 2013 +0100
+++ b/test/tools/javac/lambda/8016177/T8016177c.java	Thu Aug 22 11:48:49 2013 +0100
@@ -32,16 +32,16 @@
         m2((Integer x)->x); //ok - explicit lambda - subtyping picks most specific
         m3((Integer x)->x); //ok - explicit lambda (only one applicable)
         
-        m1(x->1); //ambiguous - stuck lambda
-        m2(x->1); //ambiguous - stuck lambda
+        m1(x->1); //ok - stuck lambda but nominal most specific wins
+        m2(x->1); //ok - stuck lambda but nominal most specific wins
         m3(x->1); //ambiguous - implicit lambda & different params
 
         m1(this::g1); //ok - unambiguous ref - subtyping picks most specific
         m2(this::g1); //ok - unambiguous ref - subtyping picks most specific
         m3(this::g1); //ambiguous - both applicable, neither most specific
         
-        m1(this::g2); //ambiguous - stuck mref
-        m2(this::g2); //ambiguous - stuck mref
+        m1(this::g2); //ok - stuck mref but nominal most specific wins
+        m2(this::g2); //ok - stuck mref but nominal most specific wins
         m3(this::g2); //ambiguous - different params
     }
 }
--- a/test/tools/javac/lambda/8016177/T8016177c.out	Tue Aug 20 18:13:09 2013 +0100
+++ b/test/tools/javac/lambda/8016177/T8016177c.out	Thu Aug 22 11:48:49 2013 +0100
@@ -1,8 +1,4 @@
-T8016177c.java:35:9: compiler.err.ref.ambiguous: m1, kindname.method, <U,V>m1(T8016177c.Function<U,V>), T8016177c, kindname.method, <U,V>m1(T8016177c.ExtFunction<U,V>), T8016177c
-T8016177c.java:36:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(T8016177c.Function<java.lang.Integer,java.lang.Integer>), T8016177c, kindname.method, m2(T8016177c.ExtFunction<java.lang.Integer,java.lang.Integer>), T8016177c
 T8016177c.java:37:9: compiler.err.ref.ambiguous: m3, kindname.method, m3(T8016177c.Function<java.lang.Integer,java.lang.Integer>), T8016177c, kindname.method, m3(T8016177c.ExtFunction<java.lang.Object,java.lang.Integer>), T8016177c
 T8016177c.java:41:9: compiler.err.ref.ambiguous: m3, kindname.method, m3(T8016177c.Function<java.lang.Integer,java.lang.Integer>), T8016177c, kindname.method, m3(T8016177c.ExtFunction<java.lang.Object,java.lang.Integer>), T8016177c
-T8016177c.java:43:9: compiler.err.ref.ambiguous: m1, kindname.method, <U,V>m1(T8016177c.Function<U,V>), T8016177c, kindname.method, <U,V>m1(T8016177c.ExtFunction<U,V>), T8016177c
-T8016177c.java:44:9: compiler.err.ref.ambiguous: m2, kindname.method, m2(T8016177c.Function<java.lang.Integer,java.lang.Integer>), T8016177c, kindname.method, m2(T8016177c.ExtFunction<java.lang.Integer,java.lang.Integer>), T8016177c
 T8016177c.java:45:9: compiler.err.ref.ambiguous: m3, kindname.method, m3(T8016177c.Function<java.lang.Integer,java.lang.Integer>), T8016177c, kindname.method, m3(T8016177c.ExtFunction<java.lang.Object,java.lang.Integer>), T8016177c
-7 errors
+3 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/8016177/T8016177g.java	Thu Aug 22 11:48:49 2013 +0100
@@ -0,0 +1,37 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8016081 8016178
+ * @summary structural most specific and stuckness
+ * @compile/fail/ref=T8016177g.out -XDrawDiagnostics T8016177g.java
+ */
+
+
+class Test {
+
+    interface Function<X, Y> {
+        Y m(X x);
+    }
+
+    interface Box<T> {
+        T get();
+        <R> R map(Function<T,R> f);
+    }
+    
+    static class Person {
+        Person(String name) { }
+    }
+
+    void print(Object arg) { }
+    void print(String arg) { }
+
+    int abs(int a) { return 0; }
+    long abs(long a) { return 0; }
+    float abs(float a) { return 0; }
+    double abs(double a) { return 0; }
+
+    void test() {
+        Box<String> b = null;
+        print(b.map(s -> new Person(s)));
+        int i = abs(b.map(s -> Double.valueOf(s)));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/8016177/T8016177g.out	Thu Aug 22 11:48:49 2013 +0100
@@ -0,0 +1,2 @@
+T8016177g.java:35:20: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: double, int)
+1 error