提交 10f923ad 编写于 作者: M mcimadamore

8000931: Cleanup Resolve.java

Summary: Unify all method resolution routines
Reviewed-by: jjg
上级 711b54cc
...@@ -502,7 +502,7 @@ public class Lower extends TreeTranslator { ...@@ -502,7 +502,7 @@ public class Lower extends TreeTranslator {
JCNewClass tree = make.NewClass(null, JCNewClass tree = make.NewClass(null,
null, make.QualIdent(ctype.tsym), args, null); null, make.QualIdent(ctype.tsym), args, null);
tree.constructor = rs.resolveConstructor( tree.constructor = rs.resolveConstructor(
make_pos, attrEnv, ctype, TreeInfo.types(args), null, false, false); make_pos, attrEnv, ctype, TreeInfo.types(args), List.<Type>nil());
tree.type = ctype; tree.type = ctype;
return tree; return tree;
} }
......
...@@ -51,6 +51,8 @@ import java.util.Collection; ...@@ -51,6 +51,8 @@ import java.util.Collection;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -450,22 +452,9 @@ public class Resolve { ...@@ -450,22 +452,9 @@ public class Resolve {
List<Type> typeargtypes, List<Type> typeargtypes,
boolean allowBoxing, boolean allowBoxing,
boolean useVarargs, boolean useVarargs,
Warner warn) Warner warn) throws Infer.InferenceException {
throws Infer.InferenceException {
if (useVarargs && (m.flags() & VARARGS) == 0) {
//better error recovery - if we stumbled upon a non-varargs method
//during varargs applicability phase, the method should be treated as
//not applicable; the reason for inapplicability can be found in the
//candidate for 'm' that was created during the BOX phase.
Candidate prevCandidate = currentResolutionContext.getCandidate(m, BOX);
JCDiagnostic details = null;
if (prevCandidate != null && !prevCandidate.isApplicable()) {
details = prevCandidate.details;
}
throw inapplicableMethodException.setMessage(details);
}
Type mt = types.memberType(site, m);
Type mt = types.memberType(site, m);
// tvars is the list of formal type variables for which type arguments // tvars is the list of formal type variables for which type arguments
// need to inferred. // need to inferred.
List<Type> tvars = List.nil(); List<Type> tvars = List.nil();
...@@ -1023,8 +1012,11 @@ public class Resolve { ...@@ -1023,8 +1012,11 @@ public class Resolve {
boolean allowBoxing, boolean allowBoxing,
boolean useVarargs, boolean useVarargs,
boolean operator) { boolean operator) {
if (sym.kind == ERR) return bestSoFar; if (sym.kind == ERR ||
if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar; !sym.isInheritedIn(site.tsym, types) ||
(useVarargs && (sym.flags() & VARARGS) == 0)) {
return bestSoFar;
}
Assert.check(sym.kind < AMBIGUOUS); Assert.check(sym.kind < AMBIGUOUS);
try { try {
Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes, Type mt = rawInstantiate(env, site, sym, null, argtypes, typeargtypes,
...@@ -1035,13 +1027,13 @@ public class Resolve { ...@@ -1035,13 +1027,13 @@ public class Resolve {
if (!operator) if (!operator)
currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic()); currentResolutionContext.addInapplicableCandidate(sym, ex.getDiagnostic());
switch (bestSoFar.kind) { switch (bestSoFar.kind) {
case ABSENT_MTH: case ABSENT_MTH:
return new InapplicableSymbolError(currentResolutionContext); return new InapplicableSymbolError(currentResolutionContext);
case WRONG_MTH: case WRONG_MTH:
if (operator) return bestSoFar; if (operator) return bestSoFar;
bestSoFar = new InapplicableSymbolsError(currentResolutionContext); bestSoFar = new InapplicableSymbolsError(currentResolutionContext);
default: default:
return bestSoFar; return bestSoFar;
} }
} }
if (!isAccessible(env, site, sym)) { if (!isAccessible(env, site, sym)) {
...@@ -1330,7 +1322,7 @@ public class Resolve { ...@@ -1330,7 +1322,7 @@ public class Resolve {
} }
} }
Symbol lookupMethod(Env<AttrContext> env, Symbol findMethodInScope(Env<AttrContext> env,
Type site, Type site,
Name name, Name name,
List<Type> argtypes, List<Type> argtypes,
...@@ -1414,7 +1406,7 @@ public class Resolve { ...@@ -1414,7 +1406,7 @@ public class Resolve {
List<Type>[] itypes = (List<Type>[])new List[] { List.<Type>nil(), List.<Type>nil() }; List<Type>[] itypes = (List<Type>[])new List[] { List.<Type>nil(), List.<Type>nil() };
InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK; InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK;
for (TypeSymbol s : superclasses(intype)) { for (TypeSymbol s : superclasses(intype)) {
bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
s.members(), bestSoFar, allowBoxing, useVarargs, operator, true); s.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
if (name == names.init) return bestSoFar; if (name == names.init) return bestSoFar;
iphase = (iphase == null) ? null : iphase.update(s, this); iphase = (iphase == null) ? null : iphase.update(s, this);
...@@ -1436,7 +1428,7 @@ public class Resolve { ...@@ -1436,7 +1428,7 @@ public class Resolve {
if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure()) if (!itype.isInterface()) continue; //skip j.l.Object (included by Types.closure())
if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && if (iphase2 == InterfaceLookupPhase.DEFAULT_OK &&
(itype.tsym.flags() & DEFAULT) == 0) continue; (itype.tsym.flags() & DEFAULT) == 0) continue;
bestSoFar = lookupMethod(env, site, name, argtypes, typeargtypes, bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true); itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
if (concrete != bestSoFar && if (concrete != bestSoFar &&
concrete.kind < ERR && bestSoFar.kind < ERR && concrete.kind < ERR && bestSoFar.kind < ERR &&
...@@ -1936,7 +1928,7 @@ public class Resolve { ...@@ -1936,7 +1928,7 @@ public class Resolve {
((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym; ((InapplicableSymbolError)errSym).errCandidate().sym : accessedSym;
List<Type> argtypes2 = Type.map(argtypes, List<Type> argtypes2 = Type.map(argtypes,
deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.firstErroneousResolutionPhase())); deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, msym, currentResolutionContext.step));
if (msym != accessedSym) { if (msym != accessedSym) {
//fixup deferred type caches - this 'hack' is required because the symbol //fixup deferred type caches - this 'hack' is required because the symbol
...@@ -2030,33 +2022,14 @@ public class Resolve { ...@@ -2030,33 +2022,14 @@ public class Resolve {
Name name, Name name,
List<Type> argtypes, List<Type> argtypes,
List<Type> typeargtypes) { List<Type> typeargtypes) {
MethodResolutionContext prevResolutionContext = currentResolutionContext; return lookupMethod(env, pos, env.enclClass.sym, new BasicLookupHelper(name, env.enclClass.type, argtypes, typeargtypes) {
try { @Override
currentResolutionContext = new MethodResolutionContext(); Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
Symbol sym = methodNotFound; return findFun(env, name, argtypes, typeargtypes,
List<MethodResolutionPhase> steps = methodResolutionSteps; phase.isBoxingRequired(),
while (steps.nonEmpty() && phase.isVarargsRequired());
steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
sym.kind >= ERRONEOUS) {
currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
sym = findFun(env, name, argtypes, typeargtypes,
steps.head.isBoxingRequired,
steps.head.isVarargsRequired);
currentResolutionContext.resolutionCache.put(steps.head, sym);
steps = steps.tail;
}
if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
MethodResolutionPhase errPhase =
currentResolutionContext.firstErroneousResolutionPhase();
sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase),
pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
env.info.pendingResolutionPhase = errPhase;
} }
return sym; });
}
finally {
currentResolutionContext = prevResolutionContext;
}
} }
/** Resolve a qualified method identifier /** Resolve a qualified method identifier
...@@ -2082,40 +2055,27 @@ public class Resolve { ...@@ -2082,40 +2055,27 @@ public class Resolve {
DiagnosticPosition pos, Env<AttrContext> env, DiagnosticPosition pos, Env<AttrContext> env,
Symbol location, Type site, Name name, List<Type> argtypes, Symbol location, Type site, Name name, List<Type> argtypes,
List<Type> typeargtypes) { List<Type> typeargtypes) {
MethodResolutionContext prevResolutionContext = currentResolutionContext; return lookupMethod(env, pos, location, resolveContext, new BasicLookupHelper(name, site, argtypes, typeargtypes) {
try { @Override
currentResolutionContext = resolveContext; Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
Symbol sym = methodNotFound; return findMethod(env, site, name, argtypes, typeargtypes,
List<MethodResolutionPhase> steps = methodResolutionSteps; phase.isBoxingRequired(),
while (steps.nonEmpty() && phase.isVarargsRequired(), false);
steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
sym.kind >= ERRONEOUS) {
currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
sym = findMethod(env, site, name, argtypes, typeargtypes,
steps.head.isBoxingRequired(),
steps.head.isVarargsRequired(), false);
currentResolutionContext.resolutionCache.put(steps.head, sym);
steps = steps.tail;
} }
if (sym.kind >= AMBIGUOUS) { @Override
//if nothing is found return the 'first' error Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
MethodResolutionPhase errPhase = if (sym.kind >= AMBIGUOUS) {
currentResolutionContext.firstErroneousResolutionPhase(); sym = super.access(env, pos, location, sym);
sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase), } else if (allowMethodHandles) {
pos, location, site, name, true, argtypes, typeargtypes); MethodSymbol msym = (MethodSymbol)sym;
env.info.pendingResolutionPhase = errPhase; if (msym.isSignaturePolymorphic(types)) {
} else if (allowMethodHandles) { env.info.pendingResolutionPhase = BASIC;
MethodSymbol msym = (MethodSymbol)sym; return findPolymorphicSignatureInstance(env, sym, argtypes);
if (msym.isSignaturePolymorphic(types)) { }
env.info.pendingResolutionPhase = BASIC;
return findPolymorphicSignatureInstance(env, sym, argtypes);
} }
return sym;
} }
return sym; });
}
finally {
currentResolutionContext = prevResolutionContext;
}
} }
/** Find or create an implicit method of exactly the given type (after erasure). /** Find or create an implicit method of exactly the given type (after erasure).
...@@ -2183,38 +2143,53 @@ public class Resolve { ...@@ -2183,38 +2143,53 @@ public class Resolve {
List<Type> typeargtypes) { List<Type> typeargtypes) {
return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes); return resolveConstructor(new MethodResolutionContext(), pos, env, site, argtypes, typeargtypes);
} }
private Symbol resolveConstructor(MethodResolutionContext resolveContext, private Symbol resolveConstructor(MethodResolutionContext resolveContext,
DiagnosticPosition pos, final DiagnosticPosition pos,
Env<AttrContext> env, Env<AttrContext> env,
Type site, Type site,
List<Type> argtypes, List<Type> argtypes,
List<Type> typeargtypes) { List<Type> typeargtypes) {
MethodResolutionContext prevResolutionContext = currentResolutionContext; return lookupMethod(env, pos, site.tsym, resolveContext, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
try { @Override
currentResolutionContext = resolveContext; Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
Symbol sym = methodNotFound; return findConstructor(pos, env, site, argtypes, typeargtypes,
List<MethodResolutionPhase> steps = methodResolutionSteps; phase.isBoxingRequired(),
while (steps.nonEmpty() && phase.isVarargsRequired());
steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
sym.kind >= ERRONEOUS) {
currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
sym = findConstructor(pos, env, site, argtypes, typeargtypes,
steps.head.isBoxingRequired(),
steps.head.isVarargsRequired());
currentResolutionContext.resolutionCache.put(steps.head, sym);
steps = steps.tail;
}
if (sym.kind >= AMBIGUOUS) {//if nothing is found return the 'first' error
MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
sym = accessMethod(currentResolutionContext.resolutionCache.get(errPhase),
pos, site, names.init, true, argtypes, typeargtypes);
env.info.pendingResolutionPhase = errPhase;
} }
return sym; });
} }
finally {
currentResolutionContext = prevResolutionContext; /** Resolve a constructor, throw a fatal error if not found.
} * @param pos The position to use for error reporting.
* @param env The environment current at the method invocation.
* @param site The type to be constructed.
* @param argtypes The types of the invocation's value arguments.
* @param typeargtypes The types of the invocation's type arguments.
*/
public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
Type site,
List<Type> argtypes,
List<Type> typeargtypes) {
MethodResolutionContext resolveContext = new MethodResolutionContext();
resolveContext.internalResolution = true;
Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
if (sym.kind == MTH) return (MethodSymbol)sym;
else throw new FatalError(
diags.fragment("fatal.err.cant.locate.ctor", site));
}
Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
Type site, List<Type> argtypes,
List<Type> typeargtypes,
boolean allowBoxing,
boolean useVarargs) {
Symbol sym = findMethod(env, site,
names.init, argtypes,
typeargtypes, allowBoxing,
useVarargs, false);
chk.checkDeprecated(pos, env.info.scope.owner, sym);
return sym;
} }
/** Resolve constructor using diamond inference. /** Resolve constructor using diamond inference.
...@@ -2232,47 +2207,36 @@ public class Resolve { ...@@ -2232,47 +2207,36 @@ public class Resolve {
Type site, Type site,
List<Type> argtypes, List<Type> argtypes,
List<Type> typeargtypes) { List<Type> typeargtypes) {
MethodResolutionContext prevResolutionContext = currentResolutionContext; return lookupMethod(env, pos, site.tsym, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
try { @Override
currentResolutionContext = new MethodResolutionContext(); Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
Symbol sym = methodNotFound; return findDiamond(env, site, argtypes, typeargtypes,
List<MethodResolutionPhase> steps = methodResolutionSteps; phase.isBoxingRequired(),
while (steps.nonEmpty() && phase.isVarargsRequired());
steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
sym.kind >= ERRONEOUS) {
currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
sym = findDiamond(env, site, argtypes, typeargtypes,
steps.head.isBoxingRequired(),
steps.head.isVarargsRequired());
currentResolutionContext.resolutionCache.put(steps.head, sym);
steps = steps.tail;
} }
if (sym.kind >= AMBIGUOUS) { @Override
Symbol errSym = Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
currentResolutionContext.resolutionCache.get(currentResolutionContext.firstErroneousResolutionPhase()); if (sym.kind >= AMBIGUOUS) {
final JCDiagnostic details = errSym.kind == WRONG_MTH ? final JCDiagnostic details = sym.kind == WRONG_MTH ?
((InapplicableSymbolError)errSym).errCandidate().details : ((InapplicableSymbolError)sym).errCandidate().details :
null; null;
errSym = new InapplicableSymbolError(errSym.kind, "diamondError", currentResolutionContext) { sym = new InapplicableSymbolError(sym.kind, "diamondError", currentResolutionContext) {
@Override @Override
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) { Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
String key = details == null ? String key = details == null ?
"cant.apply.diamond" : "cant.apply.diamond" :
"cant.apply.diamond.1"; "cant.apply.diamond.1";
return diags.create(dkind, log.currentSource(), pos, key, return diags.create(dkind, log.currentSource(), pos, key,
diags.fragment("diamond", site.tsym), details); diags.fragment("diamond", site.tsym), details);
} }
}; };
MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase(); sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
sym = accessMethod(errSym, pos, site, names.init, true, argtypes, typeargtypes); env.info.pendingResolutionPhase = currentResolutionContext.step;
env.info.pendingResolutionPhase = errPhase; }
return sym;
} }
return sym; });
}
finally {
currentResolutionContext = prevResolutionContext;
}
} }
/** This method scans all the constructor symbol in a given class scope - /** This method scans all the constructor symbol in a given class scope -
...@@ -2319,6 +2283,58 @@ public class Resolve { ...@@ -2319,6 +2283,58 @@ public class Resolve {
return bestSoFar; return bestSoFar;
} }
/** Resolve operator.
* @param pos The position to use for error reporting.
* @param optag The tag of the operation tree.
* @param env The environment current at the operation.
* @param argtypes The types of the operands.
*/
Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
Env<AttrContext> env, List<Type> argtypes) {
MethodResolutionContext prevResolutionContext = currentResolutionContext;
try {
currentResolutionContext = new MethodResolutionContext();
Name name = treeinfo.operatorName(optag);
Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
null, false, false, true);
if (boxingEnabled && sym.kind >= WRONG_MTHS)
sym = findMethod(env, syms.predefClass.type, name, argtypes,
null, true, false, true);
return accessMethod(sym, pos, env.enclClass.sym.type, name,
false, argtypes, null);
}
finally {
currentResolutionContext = prevResolutionContext;
}
}
/** Resolve operator.
* @param pos The position to use for error reporting.
* @param optag The tag of the operation tree.
* @param env The environment current at the operation.
* @param arg The type of the operand.
*/
Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) {
return resolveOperator(pos, optag, env, List.of(arg));
}
/** Resolve binary operator.
* @param pos The position to use for error reporting.
* @param optag The tag of the operation tree.
* @param env The environment current at the operation.
* @param left The types of the left operand.
* @param right The types of the right operand.
*/
Symbol resolveBinaryOperator(DiagnosticPosition pos,
JCTree.Tag optag,
Env<AttrContext> env,
Type left,
Type right) {
return resolveOperator(pos, optag, env, List.of(left, right));
}
/** /**
* Resolution of member references is typically done as a single * Resolution of member references is typically done as a single
* overload resolution step, where the argument types A are inferred from * overload resolution step, where the argument types A are inferred from
...@@ -2352,17 +2368,18 @@ public class Resolve { ...@@ -2352,17 +2368,18 @@ public class Resolve {
Name name, List<Type> argtypes, Name name, List<Type> argtypes,
List<Type> typeargtypes, List<Type> typeargtypes,
boolean boxingAllowed) { boolean boxingAllowed) {
MethodResolutionPhase maxPhase = boxingAllowed ? VARARITY : BASIC;
//step 1 - bound lookup //step 1 - bound lookup
ReferenceLookupHelper boundLookupHelper = name.equals(names.init) ? ReferenceLookupHelper boundLookupHelper = name.equals(names.init) ?
new ConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, boxingAllowed) : new ConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, maxPhase) :
new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, boxingAllowed); new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup()); Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup());
Symbol boundSym = findMemberReference(boundEnv, boundLookupHelper); Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, boundLookupHelper);
//step 2 - unbound lookup //step 2 - unbound lookup
ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup(); ReferenceLookupHelper unboundLookupHelper = boundLookupHelper.unboundLookup();
Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup()); Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup());
Symbol unboundSym = findMemberReference(unboundEnv, unboundLookupHelper); Symbol unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, unboundLookupHelper);
//merge results //merge results
Pair<Symbol, ReferenceLookupHelper> res; Pair<Symbol, ReferenceLookupHelper> res;
...@@ -2399,11 +2416,23 @@ public class Resolve { ...@@ -2399,11 +2416,23 @@ public class Resolve {
/** type arguments used during the lookup */ /** type arguments used during the lookup */
List<Type> typeargtypes; List<Type> typeargtypes;
LookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes) { /** Max overload resolution phase handled by this helper */
MethodResolutionPhase maxPhase;
LookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
this.name = name; this.name = name;
this.site = site; this.site = site;
this.argtypes = argtypes; this.argtypes = argtypes;
this.typeargtypes = typeargtypes; this.typeargtypes = typeargtypes;
this.maxPhase = maxPhase;
}
/**
* Should lookup stop at given phase with given result
*/
protected boolean shouldStop(Symbol sym, MethodResolutionPhase phase) {
return phase.ordinal() > maxPhase.ordinal() ||
sym.kind < ERRONEOUS || sym.kind == AMBIGUOUS;
} }
/** /**
...@@ -2415,7 +2444,23 @@ public class Resolve { ...@@ -2415,7 +2444,23 @@ public class Resolve {
/** /**
* Validate the result of the lookup * Validate the result of the lookup
*/ */
abstract Symbol access(Env<AttrContext> env, Symbol symbol); abstract Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym);
}
abstract class BasicLookupHelper extends LookupHelper {
BasicLookupHelper(Name name, Type site, List<Type> argtypes, List<Type> typeargtypes) {
super(name, site, argtypes, typeargtypes, MethodResolutionPhase.VARARITY);
}
@Override
Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
if (sym.kind >= AMBIGUOUS) {
//if nothing is found return the 'first' error
sym = accessMethod(sym, pos, location, site, name, true, argtypes, typeargtypes);
}
return sym;
}
} }
/** /**
...@@ -2429,14 +2474,11 @@ public class Resolve { ...@@ -2429,14 +2474,11 @@ public class Resolve {
/** The member reference tree */ /** The member reference tree */
JCMemberReference referenceTree; JCMemberReference referenceTree;
/** Max overload resolution phase handled by this helper */
MethodResolutionPhase maxPhase;
ReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, ReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) { List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
super(name, site, argtypes, typeargtypes); super(name, site, argtypes, typeargtypes, maxPhase);
this.referenceTree = referenceTree; this.referenceTree = referenceTree;
this.maxPhase = boxingAllowed ? VARARITY : BASIC;
} }
/** /**
...@@ -2445,13 +2487,13 @@ public class Resolve { ...@@ -2445,13 +2487,13 @@ public class Resolve {
*/ */
ReferenceLookupHelper unboundLookup() { ReferenceLookupHelper unboundLookup() {
//dummy loopkup helper that always return 'methodNotFound' //dummy loopkup helper that always return 'methodNotFound'
return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase.isBoxingRequired()) { return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase) {
@Override @Override
ReferenceLookupHelper unboundLookup() { ReferenceLookupHelper unboundLookup() {
return this; return this;
} }
@Override @Override
Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) { Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
return methodNotFound; return methodNotFound;
} }
@Override @Override
...@@ -2467,23 +2509,8 @@ public class Resolve { ...@@ -2467,23 +2509,8 @@ public class Resolve {
*/ */
abstract JCMemberReference.ReferenceKind referenceKind(Symbol sym); abstract JCMemberReference.ReferenceKind referenceKind(Symbol sym);
@Override Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) { //skip error reporting
return (env.info.pendingResolutionPhase.ordinal() > maxPhase.ordinal()) ?
methodNotFound : lookupReference(env, phase);
}
abstract Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase);
Symbol access(Env<AttrContext> env, Symbol sym) {
if (sym.kind >= AMBIGUOUS) {
MethodResolutionPhase errPhase = currentResolutionContext.firstErroneousResolutionPhase();
if (errPhase.ordinal() > maxPhase.ordinal()) {
errPhase = maxPhase;
}
env.info.pendingResolutionPhase = errPhase;
sym = currentResolutionContext.resolutionCache.get(errPhase);
}
return sym; return sym;
} }
} }
...@@ -2497,8 +2524,8 @@ public class Resolve { ...@@ -2497,8 +2524,8 @@ public class Resolve {
class MethodReferenceLookupHelper extends ReferenceLookupHelper { class MethodReferenceLookupHelper extends ReferenceLookupHelper {
MethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, MethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) { List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
super(referenceTree, name, site, argtypes, typeargtypes, boxingAllowed); super(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
} }
protected Symbol lookupReferenceInternal(Env<AttrContext> env, MethodResolutionPhase phase) { protected Symbol lookupReferenceInternal(Env<AttrContext> env, MethodResolutionPhase phase) {
...@@ -2513,7 +2540,7 @@ public class Resolve { ...@@ -2513,7 +2540,7 @@ public class Resolve {
} }
@Override @Override
final Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) { final Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
return adjustLookupResult(env, lookupReferenceInternal(env, phase)); return adjustLookupResult(env, lookupReferenceInternal(env, phase));
} }
...@@ -2523,7 +2550,7 @@ public class Resolve { ...@@ -2523,7 +2550,7 @@ public class Resolve {
argtypes.nonEmpty() && argtypes.nonEmpty() &&
types.isSubtypeUnchecked(argtypes.head, site)) { types.isSubtypeUnchecked(argtypes.head, site)) {
return new UnboundMethodReferenceLookupHelper(referenceTree, name, return new UnboundMethodReferenceLookupHelper(referenceTree, name,
site, argtypes, typeargtypes, maxPhase.isBoxingRequired()); site, argtypes, typeargtypes, maxPhase);
} else { } else {
return super.unboundLookup(); return super.unboundLookup();
} }
...@@ -2553,10 +2580,10 @@ public class Resolve { ...@@ -2553,10 +2580,10 @@ public class Resolve {
class UnboundMethodReferenceLookupHelper extends MethodReferenceLookupHelper { class UnboundMethodReferenceLookupHelper extends MethodReferenceLookupHelper {
UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
List<Type> argtypes, List<Type> typeargtypes, boolean boxingAllowed) { List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
super(referenceTree, name, super(referenceTree, name,
site.isRaw() ? types.asSuper(argtypes.head, site.tsym) : site, site.isRaw() ? types.asSuper(argtypes.head, site.tsym) : site,
argtypes.tail, typeargtypes, boxingAllowed); argtypes.tail, typeargtypes, maxPhase);
} }
@Override @Override
...@@ -2588,8 +2615,8 @@ public class Resolve { ...@@ -2588,8 +2615,8 @@ public class Resolve {
boolean needsInference; boolean needsInference;
ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes, ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes,
List<Type> typeargtypes, boolean boxingAllowed) { List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
super(referenceTree, names.init, site, argtypes, typeargtypes, boxingAllowed); super(referenceTree, names.init, site, argtypes, typeargtypes, maxPhase);
if (site.isRaw()) { if (site.isRaw()) {
this.site = new ClassType(site.getEnclosingType(), site.tsym.type.getTypeArguments(), site.tsym); this.site = new ClassType(site.getEnclosingType(), site.tsym.type.getTypeArguments(), site.tsym);
needsInference = true; needsInference = true;
...@@ -2597,7 +2624,7 @@ public class Resolve { ...@@ -2597,7 +2624,7 @@ public class Resolve {
} }
@Override @Override
protected Symbol lookupReference(Env<AttrContext> env, MethodResolutionPhase phase) { protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
Symbol sym = needsInference ? Symbol sym = needsInference ?
findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) : findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) :
findMethod(env, site, name, argtypes, typeargtypes, findMethod(env, site, name, argtypes, typeargtypes,
...@@ -2622,140 +2649,36 @@ public class Resolve { ...@@ -2622,140 +2649,36 @@ public class Resolve {
} }
/** /**
* Resolution step for member reference. This generalizes a standard * Main overload resolution routine. On each overload resolution step, a
* method/constructor lookup - on each overload resolution step, a * lookup helper class is used to perform the method/constructor lookup;
* lookup helper class is used to perform the reference lookup; at the end * at the end of the lookup, the helper is used to validate the results
* of the lookup, the helper is used to validate the results. * (this last step might trigger overload resolution diagnostics).
*/ */
Symbol findMemberReference(Env<AttrContext> env, LookupHelper lookupHelper) { Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, LookupHelper lookupHelper) {
MethodResolutionContext prevResolutionContext = currentResolutionContext; return lookupMethod(env, pos, location, new MethodResolutionContext(), lookupHelper);
try {
currentResolutionContext = new MethodResolutionContext();
Symbol sym = methodNotFound;
List<MethodResolutionPhase> steps = methodResolutionSteps;
while (steps.nonEmpty() &&
steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
sym.kind >= ERRONEOUS) {
currentResolutionContext.step = env.info.pendingResolutionPhase = steps.head;
sym = lookupHelper.lookup(env, steps.head);
currentResolutionContext.resolutionCache.put(steps.head, sym);
steps = steps.tail;
}
return lookupHelper.access(env, sym);
}
finally {
currentResolutionContext = prevResolutionContext;
}
} }
/** Resolve constructor. Symbol lookupMethod(Env<AttrContext> env, DiagnosticPosition pos, Symbol location,
* @param pos The position to use for error reporting. MethodResolutionContext resolveContext, LookupHelper lookupHelper) {
* @param env The environment current at the constructor invocation.
* @param site The type of class for which a constructor is searched.
* @param argtypes The types of the constructor invocation's value
* arguments.
* @param typeargtypes The types of the constructor invocation's type
* arguments.
* @param allowBoxing Allow boxing and varargs conversions.
* @param useVarargs Box trailing arguments into an array for varargs.
*/
Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env,
Type site, List<Type> argtypes,
List<Type> typeargtypes,
boolean allowBoxing,
boolean useVarargs) {
MethodResolutionContext prevResolutionContext = currentResolutionContext; MethodResolutionContext prevResolutionContext = currentResolutionContext;
try { try {
currentResolutionContext = new MethodResolutionContext(); Symbol bestSoFar = methodNotFound;
return findConstructor(pos, env, site, argtypes, typeargtypes, allowBoxing, useVarargs); currentResolutionContext = resolveContext;
} for (MethodResolutionPhase phase : methodResolutionSteps) {
finally { if (!phase.isApplicable(boxingEnabled, varargsEnabled) ||
currentResolutionContext = prevResolutionContext; lookupHelper.shouldStop(bestSoFar, phase)) break;
} MethodResolutionPhase prevPhase = currentResolutionContext.step;
} Symbol prevBest = bestSoFar;
currentResolutionContext.step = phase;
Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env, bestSoFar = phase.mergeResults(bestSoFar, lookupHelper.lookup(env, phase));
Type site, List<Type> argtypes, env.info.pendingResolutionPhase = (prevBest == bestSoFar) ? prevPhase : phase;
List<Type> typeargtypes, }
boolean allowBoxing, return lookupHelper.access(env, pos, location, bestSoFar);
boolean useVarargs) { } finally {
Symbol sym = findMethod(env, site,
names.init, argtypes,
typeargtypes, allowBoxing,
useVarargs, false);
chk.checkDeprecated(pos, env.info.scope.owner, sym);
return sym;
}
/** Resolve a constructor, throw a fatal error if not found.
* @param pos The position to use for error reporting.
* @param env The environment current at the method invocation.
* @param site The type to be constructed.
* @param argtypes The types of the invocation's value arguments.
* @param typeargtypes The types of the invocation's type arguments.
*/
public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env,
Type site,
List<Type> argtypes,
List<Type> typeargtypes) {
MethodResolutionContext resolveContext = new MethodResolutionContext();
resolveContext.internalResolution = true;
Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
if (sym.kind == MTH) return (MethodSymbol)sym;
else throw new FatalError(
diags.fragment("fatal.err.cant.locate.ctor", site));
}
/** Resolve operator.
* @param pos The position to use for error reporting.
* @param optag The tag of the operation tree.
* @param env The environment current at the operation.
* @param argtypes The types of the operands.
*/
Symbol resolveOperator(DiagnosticPosition pos, JCTree.Tag optag,
Env<AttrContext> env, List<Type> argtypes) {
MethodResolutionContext prevResolutionContext = currentResolutionContext;
try {
currentResolutionContext = new MethodResolutionContext();
Name name = treeinfo.operatorName(optag);
Symbol sym = findMethod(env, syms.predefClass.type, name, argtypes,
null, false, false, true);
if (boxingEnabled && sym.kind >= WRONG_MTHS)
sym = findMethod(env, syms.predefClass.type, name, argtypes,
null, true, false, true);
return accessMethod(sym, pos, env.enclClass.sym.type, name,
false, argtypes, null);
}
finally {
currentResolutionContext = prevResolutionContext; currentResolutionContext = prevResolutionContext;
} }
} }
/** Resolve operator.
* @param pos The position to use for error reporting.
* @param optag The tag of the operation tree.
* @param env The environment current at the operation.
* @param arg The type of the operand.
*/
Symbol resolveUnaryOperator(DiagnosticPosition pos, JCTree.Tag optag, Env<AttrContext> env, Type arg) {
return resolveOperator(pos, optag, env, List.of(arg));
}
/** Resolve binary operator.
* @param pos The position to use for error reporting.
* @param optag The tag of the operation tree.
* @param env The environment current at the operation.
* @param left The types of the left operand.
* @param right The types of the right operand.
*/
Symbol resolveBinaryOperator(DiagnosticPosition pos,
JCTree.Tag optag,
Env<AttrContext> env,
Type left,
Type right) {
return resolveOperator(pos, optag, env, List.of(left, right));
}
/** /**
* Resolve `c.name' where name == this or name == super. * Resolve `c.name' where name == this or name == super.
* @param pos The position to use for error reporting. * @param pos The position to use for error reporting.
...@@ -3190,20 +3113,14 @@ public class Resolve { ...@@ -3190,20 +3113,14 @@ public class Resolve {
return types.createErrorType(name, location, syms.errSymbol.type).tsym; return types.createErrorType(name, location, syms.errSymbol.type).tsym;
} }
protected boolean shouldReport(Candidate c) {
MethodResolutionPhase errPhase = resolveContext.firstErroneousResolutionPhase();
return !c.isApplicable() &&
c.step == errPhase;
}
private Candidate errCandidate() { private Candidate errCandidate() {
Candidate bestSoFar = null;
for (Candidate c : resolveContext.candidates) { for (Candidate c : resolveContext.candidates) {
if (shouldReport(c)) { if (c.isApplicable()) continue;
return c; bestSoFar = c;
}
} }
Assert.error(); Assert.checkNonNull(bestSoFar);
return null; return bestSoFar;
} }
} }
...@@ -3232,7 +3149,7 @@ public class Resolve { ...@@ -3232,7 +3149,7 @@ public class Resolve {
pos, pos,
"cant.apply.symbols", "cant.apply.symbols",
name == names.init ? KindName.CONSTRUCTOR : absentKind(kind), name == names.init ? KindName.CONSTRUCTOR : absentKind(kind),
getName(), name == names.init ? site.tsym.name : name,
argtypes); argtypes);
return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site)); return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site));
} else { } else {
...@@ -3243,24 +3160,17 @@ public class Resolve { ...@@ -3243,24 +3160,17 @@ public class Resolve {
//where //where
List<JCDiagnostic> candidateDetails(Type site) { List<JCDiagnostic> candidateDetails(Type site) {
List<JCDiagnostic> details = List.nil(); Map<Symbol, JCDiagnostic> details = new LinkedHashMap<Symbol, JCDiagnostic>();
for (Candidate c : resolveContext.candidates) { for (Candidate c : resolveContext.candidates) {
if (!shouldReport(c)) continue; if (c.isApplicable()) continue;
JCDiagnostic detailDiag = diags.fragment("inapplicable.method", JCDiagnostic detailDiag = diags.fragment("inapplicable.method",
Kinds.kindName(c.sym), Kinds.kindName(c.sym),
c.sym.location(site, types), c.sym.location(site, types),
c.sym.asMemberOf(site, types), c.sym.asMemberOf(site, types),
c.details); c.details);
details = details.prepend(detailDiag); details.put(c.sym, detailDiag);
} }
return details.reverse(); return List.from(details.values());
}
private Name getName() {
Symbol sym = resolveContext.candidates.head.sym;
return sym.name == names.init ?
sym.owner.name :
sym.name;
} }
} }
...@@ -3398,7 +3308,21 @@ public class Resolve { ...@@ -3398,7 +3308,21 @@ public class Resolve {
enum MethodResolutionPhase { enum MethodResolutionPhase {
BASIC(false, false), BASIC(false, false),
BOX(true, false), BOX(true, false),
VARARITY(true, true); VARARITY(true, true) {
@Override
public Symbol mergeResults(Symbol bestSoFar, Symbol sym) {
switch (sym.kind) {
case WRONG_MTH:
return (bestSoFar.kind == WRONG_MTH || bestSoFar.kind == WRONG_MTHS) ?
bestSoFar :
sym;
case ABSENT_MTH:
return bestSoFar;
default:
return sym;
}
}
};
boolean isBoxingRequired; boolean isBoxingRequired;
boolean isVarargsRequired; boolean isVarargsRequired;
...@@ -3420,6 +3344,10 @@ public class Resolve { ...@@ -3420,6 +3344,10 @@ public class Resolve {
return (varargsEnabled || !isVarargsRequired) && return (varargsEnabled || !isVarargsRequired) &&
(boxingEnabled || !isBoxingRequired); (boxingEnabled || !isBoxingRequired);
} }
public Symbol mergeResults(Symbol prev, Symbol sym) {
return sym;
}
} }
final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY); final List<MethodResolutionPhase> methodResolutionSteps = List.of(BASIC, BOX, VARARITY);
...@@ -3435,29 +3363,11 @@ public class Resolve { ...@@ -3435,29 +3363,11 @@ public class Resolve {
private List<Candidate> candidates = List.nil(); private List<Candidate> candidates = List.nil();
private Map<MethodResolutionPhase, Symbol> resolutionCache =
new EnumMap<MethodResolutionPhase, Symbol>(MethodResolutionPhase.class);
MethodResolutionPhase step = null; MethodResolutionPhase step = null;
private boolean internalResolution = false; private boolean internalResolution = false;
private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE; private DeferredAttr.AttrMode attrMode = DeferredAttr.AttrMode.SPECULATIVE;
private MethodResolutionPhase firstErroneousResolutionPhase() {
MethodResolutionPhase bestSoFar = BASIC;
Symbol sym = methodNotFound;
List<MethodResolutionPhase> steps = methodResolutionSteps;
while (steps.nonEmpty() &&
steps.head.isApplicable(boxingEnabled, varargsEnabled) &&
sym.kind >= WRONG_MTHS) {
sym = resolutionCache.get(steps.head);
if (sym.kind == ABSENT_MTH) break; //ignore spurious empty entries
bestSoFar = steps.head;
steps = steps.tail;
}
return bestSoFar;
}
void addInapplicableCandidate(Symbol sym, JCDiagnostic details) { void addInapplicableCandidate(Symbol sym, JCDiagnostic details) {
Candidate c = new Candidate(currentResolutionContext.step, sym, details, null); Candidate c = new Candidate(currentResolutionContext.step, sym, details, null);
candidates = candidates.append(c); candidates = candidates.append(c);
...@@ -3468,16 +3378,6 @@ public class Resolve { ...@@ -3468,16 +3378,6 @@ public class Resolve {
candidates = candidates.append(c); candidates = candidates.append(c);
} }
Candidate getCandidate(Symbol sym, MethodResolutionPhase phase) {
for (Candidate c : currentResolutionContext.candidates) {
if (c.step == phase &&
c.sym.baseSymbol() == sym.baseSymbol()) {
return c;
}
}
return null;
}
/** /**
* This class represents an overload resolution candidate. There are two * This class represents an overload resolution candidate. There are two
* kinds of candidates: applicable methods and inapplicable methods; * kinds of candidates: applicable methods and inapplicable methods;
......
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)) 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))
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)))} 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)))}
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 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 errors 3 errors
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, ?>))} 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))}
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))} 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))}
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))} 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, ?))}
3 errors 3 errors
Neg12.java:21:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2 Neg12.java:21:12: compiler.err.does.not.override.abstract: Neg12.D, m(java.lang.String), Neg12.I2
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))} 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))}
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) 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)
3 errors 3 errors
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))} 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))}
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))} 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))}
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) 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)
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) 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)
4 errors 4 errors
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))} 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))}
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))} 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))}
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))} 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))}
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))} 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))}
4 errors 4 errors
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
@TraceResolve(keys={"compiler.err.ref.ambiguous"})
class AmbiguityPrecedence {
@Candidate(applicable=Phase.BASIC)
static void m1(long l, int i) {}
@Candidate(applicable=Phase.BASIC)
static void m1(int i, long l) {}
@Candidate
static void m1(Integer i1, Integer i2) {}
@Candidate(applicable=Phase.BOX)
static void m2(Object o, Integer i) {}
@Candidate(applicable=Phase.BOX)
static void m2(Integer i, Object o) {}
@Candidate
static void m2(Integer... o) {}
{
m1(1, 1);
m2(1, 1);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册