147 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG |
147 //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG |
148 final InferenceContext inferenceContext = new InferenceContext(tvars); |
148 final InferenceContext inferenceContext = new InferenceContext(tvars); |
149 inferenceException.clear(); |
149 inferenceException.clear(); |
150 try { |
150 try { |
151 DeferredAttr.DeferredAttrContext deferredAttrContext = |
151 DeferredAttr.DeferredAttrContext deferredAttrContext = |
152 resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn); |
152 resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn); |
153 |
153 |
154 resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, |
154 resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext, |
155 argtypes, mt.getParameterTypes(), warn); |
155 argtypes, mt.getParameterTypes(), warn); |
156 |
156 |
157 if (allowGraphInference && |
157 if (allowGraphInference && |
223 throw inferenceException |
223 throw inferenceException |
224 .setMessage("infer.no.conforming.instance.exists", |
224 .setMessage("infer.no.conforming.instance.exists", |
225 inferenceContext.restvars(), mt.getReturnType(), to); |
225 inferenceContext.restvars(), mt.getReturnType(), to); |
226 } |
226 } |
227 } |
227 } |
228 //where |
228 |
229 private Type returnConstraintTarget(Type from, Type to) { |
229 Type returnConstraintTarget(Type from, Type to) { |
230 if (from.hasTag(VOID)) { |
230 if (from.hasTag(VOID)) { |
231 return syms.voidType; |
231 return syms.voidType; |
232 } else if (to.hasTag(NONE)) { |
232 } else if (to.hasTag(NONE)) { |
233 return from.isPrimitive() ? from : syms.objectType; |
233 return from.isPrimitive() ? from : syms.objectType; |
234 } else if (from.hasTag(UNDETVAR) && to.isPrimitive()) { |
234 } else if (from.hasTag(UNDETVAR) && to.isPrimitive()) { |
235 if (!allowGraphInference) { |
235 if (!allowGraphInference) { |
236 //if legacy, just return boxed type |
236 //if legacy, just return boxed type |
237 return types.boxedClass(to).type; |
|
238 } |
|
239 //if graph inference we need to skip conflicting boxed bounds... |
|
240 UndetVar uv = (UndetVar)from; |
|
241 for (Type t : uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { |
|
242 Type boundAsPrimitive = types.unboxedType(t); |
|
243 if (boundAsPrimitive == null) continue; |
|
244 if (types.isConvertible(boundAsPrimitive, to)) { |
|
245 //effectively skip return-type constraint generation (compatibility) |
|
246 return syms.objectType; |
|
247 } |
|
248 } |
|
249 return types.boxedClass(to).type; |
237 return types.boxedClass(to).type; |
250 } else { |
238 } |
251 return to; |
239 //if graph inference we need to skip conflicting boxed bounds... |
252 } |
240 UndetVar uv = (UndetVar)from; |
253 } |
241 for (Type t : uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) { |
|
242 Type boundAsPrimitive = types.unboxedType(t); |
|
243 if (boundAsPrimitive == null) continue; |
|
244 if (types.isConvertible(boundAsPrimitive, to)) { |
|
245 //effectively skip return-type constraint generation (compatibility) |
|
246 return syms.objectType; |
|
247 } |
|
248 } |
|
249 return types.boxedClass(to).type; |
|
250 } else { |
|
251 return to; |
|
252 } |
|
253 } |
254 |
254 |
255 /** |
255 /** |
256 * Infer cyclic inference variables as described in 15.12.2.8. |
256 * Infer cyclic inference variables as described in 15.12.2.8. |
257 */ |
257 */ |
258 private void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) { |
258 private void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) { |
1335 List<Type> undetvars; |
1335 List<Type> undetvars; |
1336 |
1336 |
1337 /** list of inference vars in this context */ |
1337 /** list of inference vars in this context */ |
1338 List<Type> inferencevars; |
1338 List<Type> inferencevars; |
1339 |
1339 |
1340 /** backed up inference variables */ |
|
1341 List<Type> saved_undet; |
|
1342 |
|
1343 java.util.Map<FreeTypeListener, List<Type>> freeTypeListeners = |
1340 java.util.Map<FreeTypeListener, List<Type>> freeTypeListeners = |
1344 new java.util.HashMap<FreeTypeListener, List<Type>>(); |
1341 new java.util.HashMap<FreeTypeListener, List<Type>>(); |
1345 |
1342 |
1346 List<FreeTypeListener> freetypeListeners = List.nil(); |
1343 List<FreeTypeListener> freetypeListeners = List.nil(); |
1347 |
1344 |