8000931: Cleanup Resolve.java

Sun, 04 Nov 2012 11:01:49 +0000

author
mcimadamore
date
Sun, 04 Nov 2012 11:01:49 +0000
changeset 1394
dbc94b8363dd
parent 1393
d7d932236fee
child 1395
9bce0c73583d

8000931: Cleanup Resolve.java
Summary: Unify all method resolution routines
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/comp/Lower.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
test/tools/javac/7132880/T7132880.out file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/6799605/T6799605.out file | annotate | diff | comparison | revisions
test/tools/javac/defaultMethods/Neg12.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6611449/T6611449.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/7086601/T7086601a.out file | annotate | diff | comparison | revisions
test/tools/javac/resolve/tests/AmbiguityPrecedence.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sun Nov 04 10:59:42 2012 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sun Nov 04 11:01:49 2012 +0000
     1.3 @@ -502,7 +502,7 @@
     1.4          JCNewClass tree = make.NewClass(null,
     1.5              null, make.QualIdent(ctype.tsym), args, null);
     1.6          tree.constructor = rs.resolveConstructor(
     1.7 -            make_pos, attrEnv, ctype, TreeInfo.types(args), null, false, false);
     1.8 +            make_pos, attrEnv, ctype, TreeInfo.types(args), List.<Type>nil());
     1.9          tree.type = ctype;
    1.10          return tree;
    1.11      }
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Sun Nov 04 10:59:42 2012 +0000
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Sun Nov 04 11:01:49 2012 +0000
     2.3 @@ -51,6 +51,8 @@
     2.4  import java.util.EnumMap;
     2.5  import java.util.EnumSet;
     2.6  import java.util.Iterator;
     2.7 +import java.util.LinkedHashMap;
     2.8 +import java.util.LinkedHashSet;
     2.9  import java.util.Map;
    2.10  import java.util.Set;
    2.11  
    2.12 @@ -450,22 +452,9 @@
    2.13                          List<Type> typeargtypes,
    2.14                          boolean allowBoxing,
    2.15                          boolean useVarargs,
    2.16 -                        Warner warn)
    2.17 -        throws Infer.InferenceException {
    2.18 -        if (useVarargs && (m.flags() & VARARGS) == 0) {
    2.19 -            //better error recovery - if we stumbled upon a non-varargs method
    2.20 -            //during varargs applicability phase, the method should be treated as
    2.21 -            //not applicable; the reason for inapplicability can be found in the
    2.22 -            //candidate for 'm' that was created during the BOX phase.
    2.23 -            Candidate prevCandidate = currentResolutionContext.getCandidate(m, BOX);
    2.24 -            JCDiagnostic details = null;
    2.25 -            if (prevCandidate != null && !prevCandidate.isApplicable()) {
    2.26 -                details = prevCandidate.details;
    2.27 -            }
    2.28 -            throw inapplicableMethodException.setMessage(details);
    2.29 -        }
    2.30 +                        Warner warn) throws Infer.InferenceException {
    2.31 +
    2.32          Type mt = types.memberType(site, m);
    2.33 -
    2.34          // tvars is the list of formal type variables for which type arguments
    2.35          // need to inferred.
    2.36          List<Type> tvars = List.nil();
    2.37 @@ -1023,8 +1012,11 @@
    2.38                        boolean allowBoxing,
    2.39                        boolean useVarargs,
    2.40                        boolean operator) {
    2.41 -        if (sym.kind == ERR) return bestSoFar;
    2.42 -        if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
    2.43 +        if (sym.kind == ERR ||
    2.44 +                !sym.isInheritedIn(site.tsym, types) ||
    2.45 +                (useVarargs && (sym.flags() & VARARGS) == 0)) {
    2.46 +            return bestSoFar;
    2.47 +        }
    2.48          Assert.check(sym.kind < AMBIGUOUS);
    2.49          try {
    2.50              Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
    2.51 @@ -1035,13 +1027,13 @@
    2.52              if (!operator)
    2.53                  currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic());
    2.54              switch (bestSoFar.kind) {
    2.55 -            case ABSENT_MTH:
    2.56 -                return new InapplicableSymbolError(currentResolutionContext);
    2.57 -            case WRONG_MTH:
    2.58 -                if (operator) return bestSoFar;
    2.59 -                bestSoFar = new InapplicableSymbolsError(currentResolutionContext);
    2.60 -            default:
    2.61 -                return bestSoFar;
    2.62 +                case ABSENT_MTH:
    2.63 +                    return new InapplicableSymbolError(currentResolutionContext);
    2.64 +                case WRONG_MTH:
    2.65 +                    if (operator) return bestSoFar;
    2.66 +                    bestSoFar = new InapplicableSymbolsError(currentResolutionContext);
    2.67 +                default:
    2.68 +                    return bestSoFar;
    2.69              }
    2.70          }
    2.71          if (!isAccessible(env, site, sym)) {
    2.72 @@ -1330,7 +1322,7 @@
    2.73          }
    2.74      }
    2.75  
    2.76 -    Symbol lookupMethod(Env<AttrContext> env,
    2.77 +    Symbol findMethodInScope(Env<AttrContext> env,
    2.78              Type site,
    2.79              Name name,
    2.80              List<Type> argtypes,
    2.81 @@ -1414,7 +1406,7 @@
    2.82          List<Type>[] itypes = (List<Type>[])new List[] { List.<Type>nil(), List.<Type>nil() };
    2.83          InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK;
    2.84          for (TypeSymbol s : superclasses(intype)) {
    2.85 -            bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes,
    2.86 +            bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
    2.87                      s.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
    2.88              if (name == names.init) return bestSoFar;
    2.89              iphase = (iphase == null) ? null : iphase.update(s, this);
    2.90 @@ -1436,7 +1428,7 @@
    2.91                  if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure())
    2.92                  if (iphase2 == InterfaceLookupPhase.DEFAULT_OK &&
    2.93                          (itype.tsym.flags() & DEFAULT) == 0) continue;
    2.94 -                bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes,
    2.95 +                bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
    2.96                          itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
    2.97                  if (concrete != bestSoFar &&
    2.98                          concrete.kind < ERR  && bestSoFar.kind < ERR &&
    2.99 @@ -1936,7 +1928,7 @@
   2.100                          ((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym;
   2.101  
   2.102                  List<Type> argtypes2 = Type.map(argtypes,
   2.103 -                        deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.firstErroneousResolutionPhase()));
   2.104 +                        deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.step));
   2.105  
   2.106                  if (msym != accessedSym) {
   2.107                      //fixup deferred type caches - this 'hack' is required because the symbol
   2.108 @@ -2030,33 +2022,14 @@
   2.109                           Name name,
   2.110                           List<Type> argtypes,
   2.111                           List<Type> typeargtypes) {
   2.112 -        MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.113 -        try {
   2.114 -            currentResolutionContext = new MethodResolutionContext();
   2.115 -            Symbol sym = methodNotFound;
   2.116 -            List<MethodResolutionPhase> steps = methodResolutionSteps;
   2.117 -            while (steps.nonEmpty() &&
   2.118 -                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
   2.119 -                   sym.kind >= ERRONEOUS) {
   2.120 -                currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
   2.121 -                sym = findFun(env, name, argtypes, typeargtypes,
   2.122 -                        steps.head.isBoxingRequired,
   2.123 -                        steps.head.isVarargsRequired);
   2.124 -                currentResolutionContext.resolutionCache.put(steps.head, sym);
   2.125 -                steps = steps.tail;
   2.126 +        return lookupMethod(env, pos, env.enclClass.sym, new BasicLookupHelper(name, env.enclClass.type, argtypes, typeargtypes) {
   2.127 +            @Override
   2.128 +            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.129 +                return findFun(env, name, argtypes, typeargtypes,
   2.130 +                        phase.isBoxingRequired(),
   2.131 +                        phase.isVarargsRequired());
   2.132              }
   2.133 -            if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
   2.134 -                MethodResolutionPhase errPhase =
   2.135 -                        currentResolutionContext.firstErroneousResolutionPhase();
   2.136 -                sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase),
   2.137 -                        pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
   2.138 -                env.info.pendingResolutionPhase = errPhase;
   2.139 -            }
   2.140 -            return sym;
   2.141 -        }
   2.142 -        finally {
   2.143 -            currentResolutionContext = prevResolutionContext;
   2.144 -        }
   2.145 +        });
   2.146      }
   2.147  
   2.148      /** Resolve a qualified method identifier
   2.149 @@ -2082,40 +2055,27 @@
   2.150                                    DiagnosticPosition pos, Env<AttrContext> env,
   2.151                                    Symbol location, Type site, Name name, List<Type> argtypes,
   2.152                                    List<Type> typeargtypes) {
   2.153 -        MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.154 -        try {
   2.155 -            currentResolutionContext = resolveContext;
   2.156 -            Symbol sym = methodNotFound;
   2.157 -            List<MethodResolutionPhase> steps = methodResolutionSteps;
   2.158 -            while (steps.nonEmpty() &&
   2.159 -                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
   2.160 -                   sym.kind >= ERRONEOUS) {
   2.161 -                currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
   2.162 -                sym = findMethod(env, site, name, argtypes, typeargtypes,
   2.163 -                        steps.head.isBoxingRequired(),
   2.164 -                        steps.head.isVarargsRequired(), false);
   2.165 -                currentResolutionContext.resolutionCache.put(steps.head, sym);
   2.166 -                steps = steps.tail;
   2.167 +        return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
   2.168 +            @Override
   2.169 +            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.170 +                return findMethod(env, site, name, argtypes, typeargtypes,
   2.171 +                        phase.isBoxingRequired(),
   2.172 +                        phase.isVarargsRequired(), false);
   2.173              }
   2.174 -            if (sym.kind >= AMBIGUOUS) {
   2.175 -                //if nothing is found return the 'first' error
   2.176 -                MethodResolutionPhase errPhase =
   2.177 -                        currentResolutionContext.firstErroneousResolutionPhase();
   2.178 -                sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase),
   2.179 -                        pos, location, site, name, true, argtypes, typeargtypes);
   2.180 -                env.info.pendingResolutionPhase = errPhase;
   2.181 -            } else if (allowMethodHandles) {
   2.182 -                MethodSymbol msym = (MethodSymbol)sym;
   2.183 -                if (msym.isSignaturePolymorphic(types)) {
   2.184 -                    env.info.pendingResolutionPhase = BASIC;
   2.185 -                    return findPolymorphicSignatureInstance(env, sym, argtypes);
   2.186 +            @Override
   2.187 +            Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
   2.188 +                if (sym.kind >= AMBIGUOUS) {
   2.189 +                    sym = super.access(env, pos, location, sym);
   2.190 +                } else if (allowMethodHandles) {
   2.191 +                    MethodSymbol msym = (MethodSymbol)sym;
   2.192 +                    if (msym.isSignaturePolymorphic(types)) {
   2.193 +                        env.info.pendingResolutionPhase = BASIC;
   2.194 +                        return findPolymorphicSignatureInstance(env, sym, argtypes);
   2.195 +                    }
   2.196                  }
   2.197 +                return sym;
   2.198              }
   2.199 -            return sym;
   2.200 -        }
   2.201 -        finally {
   2.202 -            currentResolutionContext = prevResolutionContext;
   2.203 -        }
   2.204 +        });
   2.205      }
   2.206  
   2.207      /** Find or create an implicit method of exactly the given type (after erasure).
   2.208 @@ -2183,38 +2143,53 @@
   2.209                                List<Type> typeargtypes) {
   2.210          return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes);
   2.211      }
   2.212 +
   2.213      private Symbol resolveConstructor(MethodResolutionContext resolveContext,
   2.214 -                              DiagnosticPosition pos,
   2.215 +                              final DiagnosticPosition pos,
   2.216                                Env<AttrContext> env,
   2.217                                Type site,
   2.218                                List<Type> argtypes,
   2.219                                List<Type> typeargtypes) {
   2.220 -        MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.221 -        try {
   2.222 -            currentResolutionContext = resolveContext;
   2.223 -            Symbol sym = methodNotFound;
   2.224 -            List<MethodResolutionPhase> steps = methodResolutionSteps;
   2.225 -            while (steps.nonEmpty() &&
   2.226 -                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
   2.227 -                   sym.kind >= ERRONEOUS) {
   2.228 -                currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
   2.229 -                sym = findConstructor(pos, env, site, argtypes, typeargtypes,
   2.230 -                        steps.head.isBoxingRequired(),
   2.231 -                        steps.head.isVarargsRequired());
   2.232 -                currentResolutionContext.resolutionCache.put(steps.head, sym);
   2.233 -                steps = steps.tail;
   2.234 +        return lookupMethod(env, pos, site.tsym, resolveContext, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
   2.235 +            @Override
   2.236 +            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.237 +                return findConstructor(pos, env, site, argtypes, typeargtypes,
   2.238 +                        phase.isBoxingRequired(),
   2.239 +                        phase.isVarargsRequired());
   2.240              }
   2.241 -            if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
   2.242 -                MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
   2.243 -                sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase),
   2.244 -                        pos, site, names.init, true, argtypes, typeargtypes);
   2.245 -                env.info.pendingResolutionPhase = errPhase;
   2.246 -            }
   2.247 -            return sym;
   2.248 -        }
   2.249 -        finally {
   2.250 -            currentResolutionContext = prevResolutionContext;
   2.251 -        }
   2.252 +        });
   2.253 +    }
   2.254 +
   2.255 +    /** Resolve a constructor, throw a fatal error if not found.
   2.256 +     *  @param pos       The position to use for error reporting.
   2.257 +     *  @param env       The environment current at the method invocation.
   2.258 +     *  @param site      The type to be constructed.
   2.259 +     *  @param argtypes  The types of the invocation's value arguments.
   2.260 +     *  @param typeargtypes  The types of the invocation's type arguments.
   2.261 +     */
   2.262 +    public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
   2.263 +                                        Type site,
   2.264 +                                        List<Type> argtypes,
   2.265 +                                        List<Type> typeargtypes) {
   2.266 +        MethodResolutionContext resolveContext = new MethodResolutionContext();
   2.267 +        resolveContext.internalResolution = true;
   2.268 +        Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
   2.269 +        if (sym.kind == MTH) return (MethodSymbol)sym;
   2.270 +        else throw new FatalError(
   2.271 +                 diags.fragment("fatal.err.cant.locate.ctor", site));
   2.272 +    }
   2.273 +
   2.274 +    Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
   2.275 +                              Type site, List<Type> argtypes,
   2.276 +                              List<Type> typeargtypes,
   2.277 +                              boolean allowBoxing,
   2.278 +                              boolean useVarargs) {
   2.279 +        Symbol sym = findMethod(env, site,
   2.280 +                                    names.init, argtypes,
   2.281 +                                    typeargtypes, allowBoxing,
   2.282 +                                    useVarargs, false);
   2.283 +        chk.checkDeprecated(pos, env.info.scope.owner, sym);
   2.284 +        return sym;
   2.285      }
   2.286  
   2.287      /** Resolve constructor using diamond inference.
   2.288 @@ -2232,47 +2207,36 @@
   2.289                                Type site,
   2.290                                List<Type> argtypes,
   2.291                                List<Type> typeargtypes) {
   2.292 -        MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.293 -        try {
   2.294 -            currentResolutionContext = new MethodResolutionContext();
   2.295 -            Symbol sym = methodNotFound;
   2.296 -            List<MethodResolutionPhase> steps = methodResolutionSteps;
   2.297 -            while (steps.nonEmpty() &&
   2.298 -                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
   2.299 -                   sym.kind >= ERRONEOUS) {
   2.300 -                currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
   2.301 -                sym = findDiamond(env, site, argtypes, typeargtypes,
   2.302 -                        steps.head.isBoxingRequired(),
   2.303 -                        steps.head.isVarargsRequired());
   2.304 -                currentResolutionContext.resolutionCache.put(steps.head, sym);
   2.305 -                steps = steps.tail;
   2.306 +        return lookupMethod(env, pos, site.tsym, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
   2.307 +            @Override
   2.308 +            Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.309 +                return findDiamond(env, site, argtypes, typeargtypes,
   2.310 +                        phase.isBoxingRequired(),
   2.311 +                        phase.isVarargsRequired());
   2.312              }
   2.313 -            if (sym.kind >= AMBIGUOUS) {
   2.314 -                Symbol errSym =
   2.315 -                        currentResolutionContext.resolutionCache.get(currentResolutionContext.firstErroneousResolutionPhase());
   2.316 -                final JCDiagnostic details = errSym.kind == WRONG_MTH ?
   2.317 -                                ((InapplicableSymbolError)errSym).errCandidate().details :
   2.318 -                                null;
   2.319 -                errSym = new InapplicableSymbolError(errSym.kind, "diamondError", currentResolutionContext) {
   2.320 -                    @Override
   2.321 -                    JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
   2.322 -                            Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
   2.323 -                        String key = details == null ?
   2.324 -                            "cant.apply.diamond" :
   2.325 -                            "cant.apply.diamond.1";
   2.326 -                        return diags.create(dkind, log.currentSource(), pos, key,
   2.327 -                                diags.fragment("diamond", site.tsym), details);
   2.328 -                    }
   2.329 -                };
   2.330 -                MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
   2.331 -                sym = accessMethod(errSym, pos, site, names.init, true, argtypes, typeargtypes);
   2.332 -                env.info.pendingResolutionPhase = errPhase;
   2.333 +            @Override
   2.334 +            Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
   2.335 +                if (sym.kind >= AMBIGUOUS) {
   2.336 +                    final JCDiagnostic details = sym.kind == WRONG_MTH ?
   2.337 +                                    ((InapplicableSymbolError)sym).errCandidate().details :
   2.338 +                                    null;
   2.339 +                    sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) {
   2.340 +                        @Override
   2.341 +                        JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
   2.342 +                                Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
   2.343 +                            String key = details == null ?
   2.344 +                                "cant.apply.diamond" :
   2.345 +                                "cant.apply.diamond.1";
   2.346 +                            return diags.create(dkind, log.currentSource(), pos, key,
   2.347 +                                    diags.fragment("diamond", site.tsym), details);
   2.348 +                        }
   2.349 +                    };
   2.350 +                    sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
   2.351 +                    env.info.pendingResolutionPhase = currentResolutionContext.step;
   2.352 +                }
   2.353 +                return sym;
   2.354              }
   2.355 -            return sym;
   2.356 -        }
   2.357 -        finally {
   2.358 -            currentResolutionContext = prevResolutionContext;
   2.359 -        }
   2.360 +        });
   2.361      }
   2.362  
   2.363      /** This method scans all the constructor symbol in a given class scope -
   2.364 @@ -2319,6 +2283,58 @@
   2.365          return bestSoFar;
   2.366      }
   2.367  
   2.368 +
   2.369 +
   2.370 +    /** Resolve operator.
   2.371 +     *  @param pos       The position to use for error reporting.
   2.372 +     *  @param optag     The tag of the operation tree.
   2.373 +     *  @param env       The environment current at the operation.
   2.374 +     *  @param argtypes  The types of the operands.
   2.375 +     */
   2.376 +    Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
   2.377 +                           Env<AttrContext> env, List<Type> argtypes) {
   2.378 +        MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.379 +        try {
   2.380 +            currentResolutionContext = new MethodResolutionContext();
   2.381 +            Name name = treeinfo.operatorName(optag);
   2.382 +            Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
   2.383 +                                    null, false, false, true);
   2.384 +            if (boxingEnabled && sym.kind >= WRONG_MTHS)
   2.385 +                sym = findMethod(env, syms.predefClass.type, name, argtypes,
   2.386 +                                 null, true, false, true);
   2.387 +            return accessMethod(sym, pos, env.enclClass.sym.type, name,
   2.388 +                          false, argtypes, null);
   2.389 +        }
   2.390 +        finally {
   2.391 +            currentResolutionContext = prevResolutionContext;
   2.392 +        }
   2.393 +    }
   2.394 +
   2.395 +    /** Resolve operator.
   2.396 +     *  @param pos       The position to use for error reporting.
   2.397 +     *  @param optag     The tag of the operation tree.
   2.398 +     *  @param env       The environment current at the operation.
   2.399 +     *  @param arg       The type of the operand.
   2.400 +     */
   2.401 +    Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) {
   2.402 +        return resolveOperator(pos, optag, env, List.of(arg));
   2.403 +    }
   2.404 +
   2.405 +    /** Resolve binary operator.
   2.406 +     *  @param pos       The position to use for error reporting.
   2.407 +     *  @param optag     The tag of the operation tree.
   2.408 +     *  @param env       The environment current at the operation.
   2.409 +     *  @param left      The types of the left operand.
   2.410 +     *  @param right     The types of the right operand.
   2.411 +     */
   2.412 +    Symbol resolveBinaryOperator(DiagnosticPosition pos,
   2.413 +                                 JCTree.Tag optag,
   2.414 +                                 Env<AttrContext> env,
   2.415 +                                 Type left,
   2.416 +                                 Type right) {
   2.417 +        return resolveOperator(pos, optag, env, List.of(left, right));
   2.418 +    }
   2.419 +
   2.420      /**
   2.421       * Resolution of member references is typically done as a single
   2.422       * overload resolution step, where the argument types A are inferred from
   2.423 @@ -2352,17 +2368,18 @@
   2.424                                    Name name, List<Type> argtypes,
   2.425                                    List<Type> typeargtypes,
   2.426                                    boolean boxingAllowed) {
   2.427 +        MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC;
   2.428          //step 1 - bound lookup
   2.429          ReferenceLookupHelper boundLookupHelper = name.equals(names.init) ?
   2.430 -                new ConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, boxingAllowed) :
   2.431 -                new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, boxingAllowed);
   2.432 +                new ConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, maxPhase) :
   2.433 +                new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
   2.434          Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup());
   2.435 -        Symbol boundSym = findMemberReference(boundEnv, boundLookupHelper);
   2.436 +        Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, boundLookupHelper);
   2.437  
   2.438          //step 2 - unbound lookup
   2.439          ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup();
   2.440          Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup());
   2.441 -        Symbol unboundSym = findMemberReference(unboundEnv, unboundLookupHelper);
   2.442 +        Symbol unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, unboundLookupHelper);
   2.443  
   2.444          //merge results
   2.445          Pair<Symbol, ReferenceLookupHelper> res;
   2.446 @@ -2399,11 +2416,23 @@
   2.447          /** type arguments used during the lookup */
   2.448          List<Type> typeargtypes;
   2.449  
   2.450 -        LookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes) {
   2.451 +        /** Max overload resolution phase handled by this helper */
   2.452 +        MethodResolutionPhase maxPhase;
   2.453 +
   2.454 +        LookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
   2.455              this.name = name;
   2.456              this.site = site;
   2.457              this.argtypes = argtypes;
   2.458              this.typeargtypes = typeargtypes;
   2.459 +            this.maxPhase = maxPhase;
   2.460 +        }
   2.461 +
   2.462 +        /**
   2.463 +         * Should lookup stop at given phase with given result
   2.464 +         */
   2.465 +        protected boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
   2.466 +            return phase.ordinal() > maxPhase.ordinal() ||
   2.467 +                    sym.kind < ERRONEOUS || sym.kind == AMBIGUOUS;
   2.468          }
   2.469  
   2.470          /**
   2.471 @@ -2415,7 +2444,23 @@
   2.472          /**
   2.473           * Validate the result of the lookup
   2.474           */
   2.475 -        abstract Symbol access(Env<AttrContext> env, Symbol symbol);
   2.476 +        abstract Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym);
   2.477 +    }
   2.478 +
   2.479 +    abstract class BasicLookupHelper extends LookupHelper {
   2.480 +
   2.481 +        BasicLookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes) {
   2.482 +            super(name, site, argtypes, typeargtypes, MethodResolutionPhase.VARARITY);
   2.483 +        }
   2.484 +
   2.485 +        @Override
   2.486 +        Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
   2.487 +            if (sym.kind >= AMBIGUOUS) {
   2.488 +                //if nothing is found return the 'first' error
   2.489 +                sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes);
   2.490 +            }
   2.491 +            return sym;
   2.492 +        }
   2.493      }
   2.494  
   2.495      /**
   2.496 @@ -2429,14 +2474,11 @@
   2.497          /** The member reference tree */
   2.498          JCMemberReference referenceTree;
   2.499  
   2.500 -        /** Max overload resolution phase handled by this helper */
   2.501 -        MethodResolutionPhase maxPhase;
   2.502 -
   2.503          ReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
   2.504 -                List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) {
   2.505 -            super(name, site, argtypes, typeargtypes);
   2.506 +                List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
   2.507 +            super(name, site, argtypes, typeargtypes, maxPhase);
   2.508              this.referenceTree = referenceTree;
   2.509 -            this.maxPhase = boxingAllowed ? VARARITY : BASIC;
   2.510 +
   2.511          }
   2.512  
   2.513          /**
   2.514 @@ -2445,13 +2487,13 @@
   2.515           */
   2.516          ReferenceLookupHelper unboundLookup() {
   2.517              //dummy loopkup helper that always return 'methodNotFound'
   2.518 -            return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase.isBoxingRequired()) {
   2.519 +            return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase) {
   2.520                  @Override
   2.521                  ReferenceLookupHelper unboundLookup() {
   2.522                      return this;
   2.523                  }
   2.524                  @Override
   2.525 -                Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.526 +                Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.527                      return methodNotFound;
   2.528                  }
   2.529                  @Override
   2.530 @@ -2467,23 +2509,8 @@
   2.531           */
   2.532          abstract JCMemberReference.ReferenceKind referenceKind(Symbol sym);
   2.533  
   2.534 -        @Override
   2.535 -        Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.536 -            return (env.info.pendingResolutionPhase.ordinal() > maxPhase.ordinal()) ?
   2.537 -                    methodNotFound : lookupReference(env, phase);
   2.538 -        }
   2.539 -
   2.540 -        abstract Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase);
   2.541 -
   2.542 -        Symbol access(Env<AttrContext> env, Symbol sym) {
   2.543 -            if (sym.kind >= AMBIGUOUS) {
   2.544 -                MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
   2.545 -                if (errPhase.ordinal() > maxPhase.ordinal()) {
   2.546 -                    errPhase = maxPhase;
   2.547 -                }
   2.548 -                env.info.pendingResolutionPhase = errPhase;
   2.549 -                sym = currentResolutionContext.resolutionCache.get(errPhase);
   2.550 -            }
   2.551 +        Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
   2.552 +            //skip error reporting
   2.553              return sym;
   2.554          }
   2.555      }
   2.556 @@ -2497,8 +2524,8 @@
   2.557      class MethodReferenceLookupHelper extends ReferenceLookupHelper {
   2.558  
   2.559          MethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
   2.560 -                List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) {
   2.561 -            super(referenceTree, name, site, argtypes, typeargtypes, boxingAllowed);
   2.562 +                List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
   2.563 +            super(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
   2.564          }
   2.565  
   2.566          protected Symbol lookupReferenceInternal(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.567 @@ -2513,7 +2540,7 @@
   2.568          }
   2.569  
   2.570          @Override
   2.571 -        final Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.572 +        final Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.573              return adjustLookupResult(env, lookupReferenceInternal(env, phase));
   2.574          }
   2.575  
   2.576 @@ -2523,7 +2550,7 @@
   2.577                      argtypes.nonEmpty() &&
   2.578                      types.isSubtypeUnchecked(argtypes.head, site)) {
   2.579                  return new UnboundMethodReferenceLookupHelper(referenceTree, name,
   2.580 -                        site, argtypes, typeargtypes, maxPhase.isBoxingRequired());
   2.581 +                        site, argtypes, typeargtypes, maxPhase);
   2.582              } else {
   2.583                  return super.unboundLookup();
   2.584              }
   2.585 @@ -2553,10 +2580,10 @@
   2.586      class UnboundMethodReferenceLookupHelper extends MethodReferenceLookupHelper {
   2.587  
   2.588          UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
   2.589 -                List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) {
   2.590 +                List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
   2.591              super(referenceTree, name,
   2.592                      site.isRaw() ? types.asSuper(argtypes.head, site.tsym) : site,
   2.593 -                    argtypes.tail, typeargtypes, boxingAllowed);
   2.594 +                    argtypes.tail, typeargtypes, maxPhase);
   2.595          }
   2.596  
   2.597          @Override
   2.598 @@ -2588,8 +2615,8 @@
   2.599          boolean needsInference;
   2.600  
   2.601          ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes,
   2.602 -                List<Type> typeargtypes, boolean boxingAllowed) {
   2.603 -            super(referenceTree, names.init, site, argtypes, typeargtypes, boxingAllowed);
   2.604 +                List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
   2.605 +            super(referenceTree, names.init, site, argtypes, typeargtypes, maxPhase);
   2.606              if (site.isRaw()) {
   2.607                  this.site = new ClassType(site.getEnclosingType(), site.tsym.type.getTypeArguments(), site.tsym);
   2.608                  needsInference = true;
   2.609 @@ -2597,7 +2624,7 @@
   2.610          }
   2.611  
   2.612          @Override
   2.613 -        protected Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.614 +        protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
   2.615              Symbol sym = needsInference ?
   2.616                  findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) :
   2.617                  findMethod(env, site, name, argtypes, typeargtypes,
   2.618 @@ -2622,140 +2649,36 @@
   2.619      }
   2.620  
   2.621      /**
   2.622 -     * Resolution step for member reference. This generalizes a standard
   2.623 -     * method/constructor lookup - on each overload resolution step, a
   2.624 -     * lookup helper class is used to perform the reference lookup; at the end
   2.625 -     * of the lookup, the helper is used to validate the results.
   2.626 +     * Main overload resolution routine. On each overload resolution step, a
   2.627 +     * lookup helper class is used to perform the method/constructor lookup;
   2.628 +     * at the end of the lookup, the helper is used to validate the results
   2.629 +     * (this last step might trigger overload resolution diagnostics).
   2.630       */
   2.631 -    Symbol findMemberReference(Env<AttrContext> env, LookupHelper lookupHelper) {
   2.632 +    Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, LookupHelper lookupHelper) {
   2.633 +        return lookupMethod(env, pos, location, new MethodResolutionContext(), lookupHelper);
   2.634 +    }
   2.635 +
   2.636 +    Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location,
   2.637 +            MethodResolutionContext resolveContext, LookupHelper lookupHelper) {
   2.638          MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.639          try {
   2.640 -            currentResolutionContext = new MethodResolutionContext();
   2.641 -            Symbol sym = methodNotFound;
   2.642 -            List<MethodResolutionPhase> steps = methodResolutionSteps;
   2.643 -            while (steps.nonEmpty() &&
   2.644 -                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
   2.645 -                   sym.kind >= ERRONEOUS) {
   2.646 -                currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
   2.647 -                sym = lookupHelper.lookup(env, steps.head);
   2.648 -                currentResolutionContext.resolutionCache.put(steps.head, sym);
   2.649 -                steps = steps.tail;
   2.650 +            Symbol bestSoFar = methodNotFound;
   2.651 +            currentResolutionContext = resolveContext;
   2.652 +            for (MethodResolutionPhase phase : methodResolutionSteps) {
   2.653 +                if (!phase.isApplicable(boxingEnabled, varargsEnabled) ||
   2.654 +                        lookupHelper.shouldStop(bestSoFar, phase)) break;
   2.655 +                MethodResolutionPhase prevPhase = currentResolutionContext.step;
   2.656 +                Symbol prevBest = bestSoFar;
   2.657 +                currentResolutionContext.step = phase;
   2.658 +                bestSoFar = phase.mergeResults(bestSoFar, lookupHelper.lookup(env, phase));
   2.659 +                env.info.pendingResolutionPhase = (prevBest == bestSoFar) ? prevPhase : phase;
   2.660              }
   2.661 -            return lookupHelper.access(env, sym);
   2.662 -        }
   2.663 -        finally {
   2.664 +            return lookupHelper.access(env, pos, location, bestSoFar);
   2.665 +        } finally {
   2.666              currentResolutionContext = prevResolutionContext;
   2.667          }
   2.668      }
   2.669  
   2.670 -    /** Resolve constructor.
   2.671 -     *  @param pos       The position to use for error reporting.
   2.672 -     *  @param env       The environment current at the constructor invocation.
   2.673 -     *  @param site      The type of class for which a constructor is searched.
   2.674 -     *  @param argtypes  The types of the constructor invocation's value
   2.675 -     *                   arguments.
   2.676 -     *  @param typeargtypes  The types of the constructor invocation's type
   2.677 -     *                   arguments.
   2.678 -     *  @param allowBoxing Allow boxing and varargs conversions.
   2.679 -     *  @param useVarargs Box trailing arguments into an array for varargs.
   2.680 -     */
   2.681 -    Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env,
   2.682 -                              Type site, List<Type> argtypes,
   2.683 -                              List<Type> typeargtypes,
   2.684 -                              boolean allowBoxing,
   2.685 -                              boolean useVarargs) {
   2.686 -        MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.687 -        try {
   2.688 -            currentResolutionContext = new MethodResolutionContext();
   2.689 -            return findConstructor(pos, env, site, argtypes, typeargtypes, allowBoxing, useVarargs);
   2.690 -        }
   2.691 -        finally {
   2.692 -            currentResolutionContext = prevResolutionContext;
   2.693 -        }
   2.694 -    }
   2.695 -
   2.696 -    Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
   2.697 -                              Type site, List<Type> argtypes,
   2.698 -                              List<Type> typeargtypes,
   2.699 -                              boolean allowBoxing,
   2.700 -                              boolean useVarargs) {
   2.701 -        Symbol sym = findMethod(env, site,
   2.702 -                                    names.init, argtypes,
   2.703 -                                    typeargtypes, allowBoxing,
   2.704 -                                    useVarargs, false);
   2.705 -        chk.checkDeprecated(pos, env.info.scope.owner, sym);
   2.706 -        return sym;
   2.707 -    }
   2.708 -
   2.709 -    /** Resolve a constructor, throw a fatal error if not found.
   2.710 -     *  @param pos       The position to use for error reporting.
   2.711 -     *  @param env       The environment current at the method invocation.
   2.712 -     *  @param site      The type to be constructed.
   2.713 -     *  @param argtypes  The types of the invocation's value arguments.
   2.714 -     *  @param typeargtypes  The types of the invocation's type arguments.
   2.715 -     */
   2.716 -    public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
   2.717 -                                        Type site,
   2.718 -                                        List<Type> argtypes,
   2.719 -                                        List<Type> typeargtypes) {
   2.720 -        MethodResolutionContext resolveContext = new MethodResolutionContext();
   2.721 -        resolveContext.internalResolution = true;
   2.722 -        Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
   2.723 -        if (sym.kind == MTH) return (MethodSymbol)sym;
   2.724 -        else throw new FatalError(
   2.725 -                 diags.fragment("fatal.err.cant.locate.ctor", site));
   2.726 -    }
   2.727 -
   2.728 -    /** Resolve operator.
   2.729 -     *  @param pos       The position to use for error reporting.
   2.730 -     *  @param optag     The tag of the operation tree.
   2.731 -     *  @param env       The environment current at the operation.
   2.732 -     *  @param argtypes  The types of the operands.
   2.733 -     */
   2.734 -    Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
   2.735 -                           Env<AttrContext> env, List<Type> argtypes) {
   2.736 -        MethodResolutionContext prevResolutionContext = currentResolutionContext;
   2.737 -        try {
   2.738 -            currentResolutionContext = new MethodResolutionContext();
   2.739 -            Name name = treeinfo.operatorName(optag);
   2.740 -            Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
   2.741 -                                    null, false, false, true);
   2.742 -            if (boxingEnabled && sym.kind >= WRONG_MTHS)
   2.743 -                sym = findMethod(env, syms.predefClass.type, name, argtypes,
   2.744 -                                 null, true, false, true);
   2.745 -            return accessMethod(sym, pos, env.enclClass.sym.type, name,
   2.746 -                          false, argtypes, null);
   2.747 -        }
   2.748 -        finally {
   2.749 -            currentResolutionContext = prevResolutionContext;
   2.750 -        }
   2.751 -    }
   2.752 -
   2.753 -    /** Resolve operator.
   2.754 -     *  @param pos       The position to use for error reporting.
   2.755 -     *  @param optag     The tag of the operation tree.
   2.756 -     *  @param env       The environment current at the operation.
   2.757 -     *  @param arg       The type of the operand.
   2.758 -     */
   2.759 -    Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) {
   2.760 -        return resolveOperator(pos, optag, env, List.of(arg));
   2.761 -    }
   2.762 -
   2.763 -    /** Resolve binary operator.
   2.764 -     *  @param pos       The position to use for error reporting.
   2.765 -     *  @param optag     The tag of the operation tree.
   2.766 -     *  @param env       The environment current at the operation.
   2.767 -     *  @param left      The types of the left operand.
   2.768 -     *  @param right     The types of the right operand.
   2.769 -     */
   2.770 -    Symbol resolveBinaryOperator(DiagnosticPosition pos,
   2.771 -                                 JCTree.Tag optag,
   2.772 -                                 Env<AttrContext> env,
   2.773 -                                 Type left,
   2.774 -                                 Type right) {
   2.775 -        return resolveOperator(pos, optag, env, List.of(left, right));
   2.776 -    }
   2.777 -
   2.778      /**
   2.779       * Resolve `c.name' where name == this or name == super.
   2.780       * @param pos           The position to use for error reporting.
   2.781 @@ -3190,20 +3113,14 @@
   2.782              return types.createErrorType(name, location, syms.errSymbol.type).tsym;
   2.783          }
   2.784  
   2.785 -        protected boolean shouldReport(Candidate c) {
   2.786 -            MethodResolutionPhase errPhase = resolveContext.firstErroneousResolutionPhase();
   2.787 -            return !c.isApplicable() &&
   2.788 -                    c.step == errPhase;
   2.789 -        }
   2.790 -
   2.791          private Candidate errCandidate() {
   2.792 +            Candidate bestSoFar = null;
   2.793              for (Candidate c : resolveContext.candidates) {
   2.794 -                if (shouldReport(c)) {
   2.795 -                    return c;
   2.796 -                }
   2.797 +                if (c.isApplicable()) continue;
   2.798 +                bestSoFar = c;
   2.799              }
   2.800 -            Assert.error();
   2.801 -            return null;
   2.802 +            Assert.checkNonNull(bestSoFar);
   2.803 +            return bestSoFar;
   2.804          }
   2.805      }
   2.806  
   2.807 @@ -3232,7 +3149,7 @@
   2.808                          pos,
   2.809                          "cant.apply.symbols",
   2.810                          name == names.init ? KindName.CONSTRUCTOR : absentKind(kind),
   2.811 -                        getName(),
   2.812 +                        name == names.init ? site.tsym.name : name,
   2.813                          argtypes);
   2.814                  return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site));
   2.815              } else {
   2.816 @@ -3243,24 +3160,17 @@
   2.817  
   2.818          //where
   2.819          List<JCDiagnostic> candidateDetails(Type site) {
   2.820 -            List<JCDiagnostic> details = List.nil();
   2.821 +            Map<Symbol, JCDiagnostic> details = new LinkedHashMap<Symbol, JCDiagnostic>();
   2.822              for (Candidate c : resolveContext.candidates) {
   2.823 -                if (!shouldReport(c)) continue;
   2.824 +                if (c.isApplicable()) continue;
   2.825                  JCDiagnostic detailDiag = diags.fragment("inapplicable.method",
   2.826                          Kinds.kindName(c.sym),
   2.827                          c.sym.location(site, types),
   2.828                          c.sym.asMemberOf(site, types),
   2.829                          c.details);
   2.830 -                details = details.prepend(detailDiag);
   2.831 +                details.put(c.sym, detailDiag);
   2.832              }
   2.833 -            return details.reverse();
   2.834 -        }
   2.835 -
   2.836 -        private Name getName() {
   2.837 -            Symbol sym = resolveContext.candidates.head.sym;
   2.838 -            return sym.name == names.init ?
   2.839 -                sym.owner.name :
   2.840 -                sym.name;
   2.841 +            return List.from(details.values());
   2.842          }
   2.843      }
   2.844  
   2.845 @@ -3398,7 +3308,21 @@
   2.846      enum MethodResolutionPhase {
   2.847          BASIC(false, false),
   2.848          BOX(true, false),
   2.849 -        VARARITY(true, true);
   2.850 +        VARARITY(true, true) {
   2.851 +            @Override
   2.852 +            public Symbol mergeResults(Symbol bestSoFar, Symbol sym) {
   2.853 +                switch (sym.kind) {
   2.854 +                    case WRONG_MTH:
   2.855 +                        return (bestSoFar.kind == WRONG_MTH || bestSoFar.kind == WRONG_MTHS) ?
   2.856 +                            bestSoFar :
   2.857 +                            sym;
   2.858 +                    case ABSENT_MTH:
   2.859 +                        return bestSoFar;
   2.860 +                    default:
   2.861 +                        return sym;
   2.862 +                }
   2.863 +            }
   2.864 +        };
   2.865  
   2.866          boolean isBoxingRequired;
   2.867          boolean isVarargsRequired;
   2.868 @@ -3420,6 +3344,10 @@
   2.869              return (varargsEnabled || !isVarargsRequired) &&
   2.870                     (boxingEnabled || !isBoxingRequired);
   2.871          }
   2.872 +
   2.873 +        public Symbol mergeResults(Symbol prev, Symbol sym) {
   2.874 +            return sym;
   2.875 +        }
   2.876      }
   2.877  
   2.878      final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
   2.879 @@ -3435,29 +3363,11 @@
   2.880  
   2.881          private List<Candidate> candidates = List.nil();
   2.882  
   2.883 -        private Map<MethodResolutionPhase, Symbol> resolutionCache =
   2.884 -            new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class);
   2.885 -
   2.886          MethodResolutionPhase step = null;
   2.887  
   2.888          private boolean internalResolution = false;
   2.889          private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
   2.890  
   2.891 -        private MethodResolutionPhase firstErroneousResolutionPhase() {
   2.892 -            MethodResolutionPhase bestSoFar = BASIC;
   2.893 -            Symbol sym = methodNotFound;
   2.894 -            List<MethodResolutionPhase> steps = methodResolutionSteps;
   2.895 -            while (steps.nonEmpty() &&
   2.896 -                   steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
   2.897 -                   sym.kind >= WRONG_MTHS) {
   2.898 -                sym = resolutionCache.get(steps.head);
   2.899 -                if (sym.kind == ABSENT_MTH) break; //ignore spurious empty entries
   2.900 -                bestSoFar = steps.head;
   2.901 -                steps = steps.tail;
   2.902 -            }
   2.903 -            return bestSoFar;
   2.904 -        }
   2.905 -
   2.906          void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
   2.907              Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
   2.908              candidates = candidates.append(c);
   2.909 @@ -3468,16 +3378,6 @@
   2.910              candidates = candidates.append(c);
   2.911          }
   2.912  
   2.913 -        Candidate getCandidate(Symbol sym, MethodResolutionPhase phase) {
   2.914 -            for (Candidate c : currentResolutionContext.candidates) {
   2.915 -                if (c.step == phase &&
   2.916 -                        c.sym.baseSymbol() == sym.baseSymbol()) {
   2.917 -                    return c;
   2.918 -                }
   2.919 -            }
   2.920 -            return null;
   2.921 -        }
   2.922 -
   2.923          /**
   2.924           * This class represents an overload resolution candidate. There are two
   2.925           * kinds of candidates: applicable methods and inapplicable methods;
     3.1 --- a/test/tools/javac/7132880/T7132880.out	Sun Nov 04 10:59:42 2012 +0000
     3.2 +++ b/test/tools/javac/7132880/T7132880.out	Sun Nov 04 11:01:49 2012 +0000
     3.3 @@ -1,4 +1,4 @@
     3.4  T7132880.java:23:12: compiler.err.cant.apply.symbol: kindname.method, m1, java.lang.Integer, java.lang.String, kindname.class, Outer.Inner1, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer))
     3.5 -T7132880.java:33:12: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.String,{(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Double), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Double))),(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Integer), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)))}
     3.6 +T7132880.java:33:12: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.String,{(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Integer), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer))),(compiler.misc.inapplicable.method: kindname.method, Outer.Inner2, m1(java.lang.Double), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Double)))}
     3.7  T7132880.java:43:12: compiler.err.ref.ambiguous: m2, kindname.method, m2(java.lang.Object,int), Outer.Inner3, kindname.method, m2(int,java.lang.Object), Outer.Inner3
     3.8  3 errors
     4.1 --- a/test/tools/javac/Diagnostics/6799605/T6799605.out	Sun Nov 04 10:59:42 2012 +0000
     4.2 +++ b/test/tools/javac/Diagnostics/6799605/T6799605.out	Sun Nov 04 11:01:49 2012 +0000
     4.3 @@ -1,4 +1,4 @@
     4.4 -T6799605.java:17:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.inferred.do.not.conform.to.upper.bounds: compiler.misc.type.captureof: 1, ?, T6799605<compiler.misc.type.captureof: 1, ?>))}
     4.5 -T6799605.java:18:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 2, ?, compiler.misc.type.captureof: 2, ?,compiler.misc.type.captureof: 1, ?)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T))}
     4.6 -T6799605.java:19:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,T6799605<compiler.misc.type.captureof: 3, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 3, ?, compiler.misc.type.captureof: 3, ?,compiler.misc.type.captureof: 2, ?,compiler.misc.type.captureof: 1, ?)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T))}
     4.7 +T6799605.java:17:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.inferred.do.not.conform.to.upper.bounds: compiler.misc.type.captureof: 1, ?, T6799605<compiler.misc.type.captureof: 1, ?>)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T))}
     4.8 +T6799605.java:18:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 2, ?, compiler.misc.type.captureof: 2, ?,compiler.misc.type.captureof: 1, ?)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T))}
     4.9 +T6799605.java:19:9: compiler.err.cant.apply.symbols: kindname.method, m, T6799605<compiler.misc.type.captureof: 1, ?>,T6799605<compiler.misc.type.captureof: 2, ?>,T6799605<compiler.misc.type.captureof: 3, ?>,{(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.method, T6799605, <T>m(T6799605<T>,T6799605<T>,T6799605<T>), (compiler.misc.inferred.do.not.conform.to.eq.bounds: compiler.misc.type.captureof: 3, ?, compiler.misc.type.captureof: 3, ?,compiler.misc.type.captureof: 2, ?,compiler.misc.type.captureof: 1, ?))}
    4.10  3 errors
     5.1 --- a/test/tools/javac/defaultMethods/Neg12.out	Sun Nov 04 10:59:42 2012 +0000
     5.2 +++ b/test/tools/javac/defaultMethods/Neg12.out	Sun Nov 04 11:01:49 2012 +0000
     5.3 @@ -1,4 +1,4 @@
     5.4  Neg12.java:21:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2
     5.5 -Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, ,{(compiler.misc.inapplicable.method: kindname.method, Neg12.B, m(java.lang.Integer), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, Neg12.I1, m(java.lang.String), (compiler.misc.arg.length.mismatch))}
     5.6 +Neg12.java:24:10: compiler.err.cant.apply.symbols: kindname.method, m, ,{(compiler.misc.inapplicable.method: kindname.method, Neg12.I1, m(java.lang.String), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, Neg12.B, m(java.lang.Integer), (compiler.misc.arg.length.mismatch))}
     5.7  Neg12.java:25:10: compiler.err.cant.apply.symbol: kindname.method, m, java.lang.Integer, compiler.misc.no.args, kindname.class, Neg12.B, (compiler.misc.arg.length.mismatch)
     5.8  3 errors
     6.1 --- a/test/tools/javac/generics/inference/6611449/T6611449.out	Sun Nov 04 10:59:42 2012 +0000
     6.2 +++ b/test/tools/javac/generics/inference/6611449/T6611449.out	Sun Nov 04 11:01:49 2012 +0000
     6.3 @@ -1,5 +1,5 @@
     6.4 -T6611449.java:18:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S))}
     6.5 -T6611449.java:19:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.infer.arg.length.mismatch: T))}
     6.6 +T6611449.java:18:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.infer.arg.length.mismatch: T))}
     6.7 +T6611449.java:19:9: compiler.err.cant.apply.symbols: kindname.constructor, T6611449, int,int,{(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T), (compiler.misc.infer.arg.length.mismatch: T)),(compiler.misc.inapplicable.method: kindname.constructor, T6611449, <T>T6611449(T,T), (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S))}
     6.8  T6611449.java:20:9: compiler.err.cant.apply.symbol: kindname.method, m1, T, int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)
     6.9  T6611449.java:21:9: compiler.err.cant.apply.symbol: kindname.method, m2, T,T, int,int, kindname.class, T6611449<S>, (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, S)
    6.10  4 errors
     7.1 --- a/test/tools/javac/generics/inference/7086601/T7086601a.out	Sun Nov 04 10:59:42 2012 +0000
     7.2 +++ b/test/tools/javac/generics/inference/7086601/T7086601a.out	Sun Nov 04 11:01:49 2012 +0000
     7.3 @@ -1,5 +1,5 @@
     7.4 -T7086601a.java:20:9: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m1(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m1(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String,java.lang.Object))}
     7.5 -T7086601a.java:24:9: compiler.err.cant.apply.symbols: kindname.method, m2, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m2(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m2(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Object))}
     7.6 -T7086601a.java:28:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String,java.lang.Object))}
     7.7 -T7086601a.java:32:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Object))}
     7.8 +T7086601a.java:20:9: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m1(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String,java.lang.Object)),(compiler.misc.inapplicable.method: kindname.method, T7086601, m1(java.lang.Object), (compiler.misc.arg.length.mismatch))}
     7.9 +T7086601a.java:24:9: compiler.err.cant.apply.symbols: kindname.method, m2, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m2(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Object)),(compiler.misc.inapplicable.method: kindname.method, T7086601, m2(java.lang.Object), (compiler.misc.arg.length.mismatch))}
    7.10 +T7086601a.java:28:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String,java.lang.Object)),(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch))}
    7.11 +T7086601a.java:32:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Object)),(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch))}
    7.12  4 errors
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/tools/javac/resolve/tests/AmbiguityPrecedence.java	Sun Nov 04 11:01:49 2012 +0000
     8.3 @@ -0,0 +1,45 @@
     8.4 +/*
     8.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.
    8.11 + *
    8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 + * version 2 for more details (a copy is included in the LICENSE file that
    8.16 + * accompanied this code).
    8.17 + *
    8.18 + * You should have received a copy of the GNU General Public License version
    8.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 + *
    8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.23 + * or visit www.oracle.com if you need additional information or have any
    8.24 + * questions.
    8.25 + */
    8.26 +
    8.27 +@TraceResolve(keys={"compiler.err.ref.ambiguous"})
    8.28 +class AmbiguityPrecedence {
    8.29 +
    8.30 +    @Candidate(applicable=Phase.BASIC)
    8.31 +    static void m1(long l, int i) {}
    8.32 +    @Candidate(applicable=Phase.BASIC)
    8.33 +    static void m1(int i, long l) {}
    8.34 +    @Candidate
    8.35 +    static void m1(Integer i1, Integer i2) {}
    8.36 +
    8.37 +    @Candidate(applicable=Phase.BOX)
    8.38 +    static void m2(Object o, Integer i) {}
    8.39 +    @Candidate(applicable=Phase.BOX)
    8.40 +    static void m2(Integer i, Object o) {}
    8.41 +    @Candidate
    8.42 +    static void m2(Integer... o) {}
    8.43 +
    8.44 +    {
    8.45 +        m1(1, 1);
    8.46 +        m2(1, 1);
    8.47 +    }
    8.48 +}

mercurial