Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.299 diff -u -r1.299 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 29 Jan 2007 07:37:02 -0000 1.299 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 28 Feb 2007 21:48:08 -0000 @@ -1114,6 +1114,7 @@ MethodBinding[] candidates = null; int candidatesCount = 0; MethodBinding problemMethod = null; + boolean searchForDefaultAbstractMethod = isCompliant14 && !receiverType.isInterface() && (receiverType.isAbstract() || receiverType.isTypeVariable()); if (foundSize > 0) { // argument type compatibility check for (int i = 0; i < foundSize; i++) { @@ -1123,7 +1124,7 @@ if (compatibleMethod.isValidBinding()) { if (foundSize == 1 && compatibleMethod.canBeSeenBy(receiverType, invocationSite, this)) { // return the single visible match now - if (isCompliant14 && (receiverType.isAbstract() || receiverType.isTypeVariable())) + if (searchForDefaultAbstractMethod) return findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, compatibleMethod); unitScope.recordTypeReferences(compatibleMethod.thrownExceptions); return compatibleMethod; @@ -1186,27 +1187,35 @@ // tiebreak using visibility check int visiblesCount = 0; - for (int i = 0; i < candidatesCount; i++) { - MethodBinding methodBinding = candidates[i]; - if (methodBinding.canBeSeenBy(receiverType, invocationSite, this)) { - if (visiblesCount != i) { - candidates[i] = null; - candidates[visiblesCount] = methodBinding; - } - visiblesCount++; - } - } - if (visiblesCount == 1) { - if (isCompliant14 && (receiverType.isAbstract() || receiverType.isTypeVariable())) - return findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, candidates[0]); - unitScope.recordTypeReferences(candidates[0].thrownExceptions); - return candidates[0]; - } - if (visiblesCount == 0) { - MethodBinding interfaceMethod = - findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, null); - if (interfaceMethod != null) return interfaceMethod; - return new ProblemMethodBinding(candidates[0], candidates[0].selector, candidates[0].parameters, ProblemReasons.NotVisible); + if (receiverType.isInterface()) { + if (candidatesCount == 1) { + unitScope.recordTypeReferences(candidates[0].thrownExceptions); + return candidates[0]; + } + visiblesCount = candidatesCount; + } else { + for (int i = 0; i < candidatesCount; i++) { + MethodBinding methodBinding = candidates[i]; + if (methodBinding.canBeSeenBy(receiverType, invocationSite, this)) { + if (visiblesCount != i) { + candidates[i] = null; + candidates[visiblesCount] = methodBinding; + } + visiblesCount++; + } + } + if (visiblesCount == 1) { + if (searchForDefaultAbstractMethod) + return findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, candidates[0]); + unitScope.recordTypeReferences(candidates[0].thrownExceptions); + return candidates[0]; + } + if (visiblesCount == 0) { + MethodBinding interfaceMethod = + findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, null); + if (interfaceMethod != null) return interfaceMethod; + return new ProblemMethodBinding(candidates[0], candidates[0].selector, candidates[0].parameters, ProblemReasons.NotVisible); + } } if (complianceLevel <= ClassFileConstants.JDK1_3) { @@ -1230,11 +1239,14 @@ } MethodBinding mostSpecificMethod = mostSpecificMethodBinding(candidates, visiblesCount, argumentTypes, invocationSite, receiverType); - if (isCompliant15 - && mostSpecificMethod.isValidBinding() - && parameterCompatibilityLevel(mostSpecificMethod, argumentTypes) > COMPATIBLE) { - // see if there is a better match in the interfaces - see AutoBoxingTest 99 + if (searchForDefaultAbstractMethod) { // search interfaces for a better match + if (mostSpecificMethod.isValidBinding()) + // see if there is a better match in the interfaces - see AutoBoxingTest 99, LookupTest#81 return findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, mostSpecificMethod); + // see if there is a match in the interfaces - see LookupTest#84 + MethodBinding interfaceMethod = findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, null); + if (interfaceMethod != null && interfaceMethod.isValidBinding() /* else return the same error as before */) + return interfaceMethod; } return mostSpecificMethod; }