src/share/classes/com/sun/tools/javac/comp/Resolve.java

changeset 2559
0253e7cc98a4
parent 2543
c6d5efccedc3
child 2611
9e80ab1dad9e
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Sep 10 10:50:59 2014 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed Sep 10 10:51:36 2014 +0100
     1.3 @@ -3045,7 +3045,7 @@
     1.4          /**
     1.5           * Should lookup stop at given phase with given result
     1.6           */
     1.7 -        protected boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
     1.8 +        final boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
     1.9              return phase.ordinal() > maxPhase.ordinal() ||
    1.10                      sym.kind < ERRONEOUS || sym.kind == AMBIGUOUS;
    1.11          }
    1.12 @@ -4228,15 +4228,39 @@
    1.13          VARARITY(true, true) {
    1.14              @Override
    1.15              public Symbol mergeResults(Symbol bestSoFar, Symbol sym) {
    1.16 -                switch (sym.kind) {
    1.17 -                    case WRONG_MTH:
    1.18 -                        return (bestSoFar.kind == WRONG_MTH || bestSoFar.kind == WRONG_MTHS) ?
    1.19 -                            bestSoFar :
    1.20 -                            sym;
    1.21 -                    case ABSENT_MTH:
    1.22 -                        return bestSoFar;
    1.23 -                    default:
    1.24 -                        return sym;
    1.25 +                //Check invariants (see {@code LookupHelper.shouldStop})
    1.26 +                Assert.check(bestSoFar.kind >= ERRONEOUS && bestSoFar.kind != AMBIGUOUS);
    1.27 +                if (sym.kind < ERRONEOUS) {
    1.28 +                    //varargs resolution successful
    1.29 +                    return sym;
    1.30 +                } else {
    1.31 +                    //pick best error
    1.32 +                    switch (bestSoFar.kind) {
    1.33 +                        case WRONG_MTH:
    1.34 +                        case WRONG_MTHS:
    1.35 +                            //Override previous errors if they were caused by argument mismatch.
    1.36 +                            //This generally means preferring current symbols - but we need to pay
    1.37 +                            //attention to the fact that the varargs lookup returns 'less' candidates
    1.38 +                            //than the previous rounds, and adjust that accordingly.
    1.39 +                            switch (sym.kind) {
    1.40 +                                case WRONG_MTH:
    1.41 +                                    //if the previous round matched more than one method, return that
    1.42 +                                    //result instead
    1.43 +                                    return bestSoFar.kind == WRONG_MTHS ?
    1.44 +                                            bestSoFar : sym;
    1.45 +                                case ABSENT_MTH:
    1.46 +                                    //do not override erroneous symbol if the arity lookup did not
    1.47 +                                    //match any method
    1.48 +                                    return bestSoFar;
    1.49 +                                case WRONG_MTHS:
    1.50 +                                default:
    1.51 +                                    //safe to override
    1.52 +                                    return sym;
    1.53 +                            }
    1.54 +                        default:
    1.55 +                            //otherwise, return first error
    1.56 +                            return bestSoFar;
    1.57 +                    }
    1.58                  }
    1.59              }
    1.60          };

mercurial