changeset 2249:654796cd8e47

8016177: structural most specific and stuckness 8016178: Order of unsticking functional expressions Improved heuristics in potentially ambiguous Xlint check (non-overlapping methods are now skipped).
author mcimadamore
date Mon, 12 Aug 2013 13:47:51 +0100
parents 0184ece97062
children e13d3a6dfaa6
files src/share/classes/com/sun/tools/javac/comp/Check.java
diffstat 1 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Aug 08 16:41:21 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Mon Aug 12 13:47:51 2013 +0100
@@ -2459,27 +2459,33 @@
             List<Type> args2 = rs.adjustArgs(mt2.getParameterTypes(), msym2, maxLength, true);
             //if arities don't match, exit
             if (args1.length() != args2.length()) return;
+            boolean potentiallyAmbiguous = false;
             while (args1.nonEmpty() && args2.nonEmpty()) {
                 Type s = args1.head;
                 Type t = args2.head;
-                if (types.isFunctionalInterface(s) && types.isFunctionalInterface(t) &&
-                        !types.isSameType(t, s) &&
-                        types.isSubtype(t, s) == types.isSubtype(s, t) &&
-                        types.findDescriptorType(s).getParameterTypes().length() > 0 &&
-                        types.findDescriptorType(s).getParameterTypes().length() ==
-                        types.findDescriptorType(t).getParameterTypes().length()) {
-                    //we found two incompatible functional interfaces with same arity
-                    //this means a call site passing an implicit lambda would be ambigiuous
-                    msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
-                    msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
-                    log.warning(LintCategory.OVERLOADS, pos, "potentially.ambiguous.overload",
-                                msym1, msym1.location(),
-                                msym2, msym2.location());
-                    return;
+                if (!types.isSubtype(t, s) && !types.isSubtype(s, t)) {
+                    if (types.isFunctionalInterface(s) && types.isFunctionalInterface(t) &&
+                            types.findDescriptorType(s).getParameterTypes().length() > 0 &&
+                            types.findDescriptorType(s).getParameterTypes().length() ==
+                            types.findDescriptorType(t).getParameterTypes().length()) {
+                        potentiallyAmbiguous = true;
+                    } else {
+                        break;
+                    }
                 }
                 args1 = args1.tail;
                 args2 = args2.tail;
             }
+            if (potentiallyAmbiguous) {
+                //we found two incompatible functional interfaces with same arity
+                //this means a call site passing an implicit lambda would be ambigiuous
+                msym1.flags_field |= POTENTIALLY_AMBIGUOUS;
+                msym2.flags_field |= POTENTIALLY_AMBIGUOUS;
+                log.warning(LintCategory.OVERLOADS, pos, "potentially.ambiguous.overload",
+                            msym1, msym1.location(),
+                            msym2, msym2.location());
+                return;
+            }
          }
      }