112 void clear() { |
112 void clear() { |
113 messages = List.nil(); |
113 messages = List.nil(); |
114 } |
114 } |
115 } |
115 } |
116 |
116 |
117 private final InferenceException inferenceException; |
117 final InferenceException inferenceException; |
118 |
118 |
119 /*************************************************************************** |
119 /*************************************************************************** |
120 * Mini/Maximization of UndetVars |
120 * Mini/Maximization of UndetVars |
121 ***************************************************************************/ |
121 ***************************************************************************/ |
122 |
122 |
269 Symbol msym, |
269 Symbol msym, |
270 List<Type> argtypes, |
270 List<Type> argtypes, |
271 boolean allowBoxing, |
271 boolean allowBoxing, |
272 boolean useVarargs, |
272 boolean useVarargs, |
273 Resolve.MethodResolutionContext resolveContext, |
273 Resolve.MethodResolutionContext resolveContext, |
|
274 Resolve.MethodCheck methodCheck, |
274 Warner warn) throws InferenceException { |
275 Warner warn) throws InferenceException { |
275 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG |
276 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG |
276 final InferenceContext inferenceContext = new InferenceContext(tvars, this, true); |
277 final InferenceContext inferenceContext = new InferenceContext(tvars, this, true); |
277 inferenceException.clear(); |
278 inferenceException.clear(); |
278 |
279 |
|
280 DeferredAttr.DeferredAttrContext deferredAttrContext = |
|
281 resolveContext.deferredAttrContext(msym, inferenceContext); |
|
282 |
279 try { |
283 try { |
280 rs.checkRawArgumentsAcceptable(env, msym, resolveContext.attrMode(), inferenceContext, |
284 methodCheck.argumentsAcceptable(env, deferredAttrContext, argtypes, mt.getParameterTypes(), warn); |
281 argtypes, mt.getParameterTypes(), allowBoxing, useVarargs, warn, |
285 |
282 new InferenceCheckHandler(inferenceContext)); |
286 deferredAttrContext.complete(); |
283 |
287 |
284 // minimize as yet undetermined type variables |
288 // minimize as yet undetermined type variables |
285 for (Type t : inferenceContext.undetvars) { |
289 for (Type t : inferenceContext.undetvars) { |
286 minimizeInst((UndetVar)t, warn); |
290 minimizeInst((UndetVar)t, warn); |
287 } |
291 } |
307 return mt; |
311 return mt; |
308 } finally { |
312 } finally { |
309 inferenceContext.notifyChange(types); |
313 inferenceContext.notifyChange(types); |
310 } |
314 } |
311 } |
315 } |
312 //where |
|
313 |
|
314 /** inference check handler **/ |
|
315 class InferenceCheckHandler implements Resolve.MethodCheckHandler { |
|
316 |
|
317 InferenceContext inferenceContext; |
|
318 |
|
319 public InferenceCheckHandler(InferenceContext inferenceContext) { |
|
320 this.inferenceContext = inferenceContext; |
|
321 } |
|
322 |
|
323 public InapplicableMethodException arityMismatch() { |
|
324 return inferenceException.setMessage("infer.arg.length.mismatch", inferenceContext.inferenceVars()); |
|
325 } |
|
326 public InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details) { |
|
327 String key = varargs ? |
|
328 "infer.varargs.argument.mismatch" : |
|
329 "infer.no.conforming.assignment.exists"; |
|
330 return inferenceException.setMessage(key, |
|
331 inferenceContext.inferenceVars(), details); |
|
332 } |
|
333 public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) { |
|
334 return inferenceException.setMessage("inaccessible.varargs.type", |
|
335 expected, Kinds.kindName(location), location); |
|
336 } |
|
337 } |
|
338 |
316 |
339 /** check that type parameters are within their bounds. |
317 /** check that type parameters are within their bounds. |
340 */ |
318 */ |
341 void checkWithinBounds(InferenceContext inferenceContext, |
319 void checkWithinBounds(InferenceContext inferenceContext, |
342 Warner warn) throws InferenceException { |
320 Warner warn) throws InferenceException { |