Lines 10-17
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.compiler.lookup; |
11 |
package org.eclipse.jdt.internal.compiler.lookup; |
12 |
|
12 |
|
13 |
import java.util.HashMap; |
|
|
14 |
import java.util.Map; |
15 |
import org.eclipse.jdt.internal.compiler.ast.MessageSend; |
13 |
import org.eclipse.jdt.internal.compiler.ast.MessageSend; |
16 |
|
14 |
|
17 |
/** |
15 |
/** |
Lines 28-34
Link Here
|
28 |
public boolean wasInferred; // only set to true for instances resulting from method invocation inferrence |
26 |
public boolean wasInferred; // only set to true for instances resulting from method invocation inferrence |
29 |
public boolean isRaw; // set to true for method behaving as raw for substitution purpose |
27 |
public boolean isRaw; // set to true for method behaving as raw for substitution purpose |
30 |
private MethodBinding tiebreakMethod; |
28 |
private MethodBinding tiebreakMethod; |
31 |
public boolean isUnchecked; // indicates whether inferred arguments used unchecked conversion during bound check or was raw |
29 |
public boolean isUnchecked; // transient flag set during inference (warning: bindings are shared, so flag cannot be trusted beyond) |
32 |
|
30 |
|
33 |
/** |
31 |
/** |
34 |
* Perform inference of generic method type parameters and/or expected type |
32 |
* Perform inference of generic method type parameters and/or expected type |
Lines 54-72
Link Here
|
54 |
|
52 |
|
55 |
// initializes the map of substitutes (var --> type[][]{ equal, extends, super} |
53 |
// initializes the map of substitutes (var --> type[][]{ equal, extends, super} |
56 |
TypeBinding[] parameters = originalMethod.parameters; |
54 |
TypeBinding[] parameters = originalMethod.parameters; |
57 |
int varLength = typeVariables.length; |
55 |
InferenceContext inferenceContext = new InferenceContext(originalMethod); |
58 |
Map collectedSubstitutes = new HashMap(varLength); |
56 |
methodSubstitute = inferFromArgumentTypes(scope, originalMethod, arguments, parameters, inferenceContext); |
59 |
for (int i = 0; i < varLength; i++) |
|
|
60 |
collectedSubstitutes.put(typeVariables[i], new TypeBinding[3][]); |
61 |
|
62 |
substitutes = new TypeBinding[varLength]; |
63 |
methodSubstitute = inferFromArgumentTypes(scope, originalMethod, arguments, parameters, collectedSubstitutes, substitutes); |
64 |
if (methodSubstitute == null) |
57 |
if (methodSubstitute == null) |
65 |
return null; |
58 |
return null; |
66 |
// substitutes may hold null to denote unresolved vars, but null arguments got replaced with respective original variable in param method |
59 |
// substitutes may hold null to denote unresolved vars, but null arguments got replaced with respective original variable in param method |
67 |
|
60 |
|
68 |
// 15.12.2.8 - inferring unresolved type arguments |
61 |
// 15.12.2.8 - inferring unresolved type arguments |
69 |
if (hasUnresolvedTypeArgument(substitutes)) { |
62 |
if (inferenceContext.hasUnresolvedTypeArgument()) { |
70 |
TypeBinding expectedType = null; |
63 |
TypeBinding expectedType = null; |
71 |
if (methodSubstitute.returnType != TypeBinding.VOID) { |
64 |
if (methodSubstitute.returnType != TypeBinding.VOID) { |
72 |
// if message invocation has expected type |
65 |
// if message invocation has expected type |
Lines 76-82
Link Here
|
76 |
} |
69 |
} |
77 |
if (expectedType == null) expectedType = scope.getJavaLangObject(); // assume Object by default |
70 |
if (expectedType == null) expectedType = scope.getJavaLangObject(); // assume Object by default |
78 |
} |
71 |
} |
79 |
methodSubstitute = methodSubstitute.inferFromExpectedType(scope, expectedType, collectedSubstitutes, substitutes); |
72 |
methodSubstitute = methodSubstitute.inferFromExpectedType(scope, expectedType, inferenceContext); |
80 |
if (methodSubstitute == null) |
73 |
if (methodSubstitute == null) |
81 |
return null; |
74 |
return null; |
82 |
} |
75 |
} |
Lines 103-128
Link Here
|
103 |
} |
96 |
} |
104 |
} |
97 |
} |
105 |
} |
98 |
} |
106 |
|
|
|
107 |
return methodSubstitute; |
99 |
return methodSubstitute; |
108 |
} |
100 |
} |
109 |
|
101 |
|
110 |
/** |
102 |
/** |
111 |
* Returns true if any unresolved variable is detected, i.e. any variable is substituted with itself |
|
|
112 |
*/ |
113 |
private static boolean hasUnresolvedTypeArgument(TypeBinding[] substitutes) { |
114 |
for (int i = 0, varLength = substitutes.length; i <varLength; i++) { |
115 |
if (substitutes[i] == null) { |
116 |
return true; |
117 |
} |
118 |
} |
119 |
return false; |
120 |
} |
121 |
|
122 |
/** |
123 |
* Collect argument type mapping, handling varargs |
103 |
* Collect argument type mapping, handling varargs |
124 |
*/ |
104 |
*/ |
125 |
private static ParameterizedGenericMethodBinding inferFromArgumentTypes(Scope scope, MethodBinding originalMethod, TypeBinding[] arguments, TypeBinding[] parameters, Map collectedSubstitutes, TypeBinding[] substitutes) { |
105 |
private static ParameterizedGenericMethodBinding inferFromArgumentTypes(Scope scope, MethodBinding originalMethod, TypeBinding[] arguments, TypeBinding[] parameters, InferenceContext inferenceContext) { |
126 |
|
106 |
|
127 |
if (originalMethod.isVarargs()) { |
107 |
if (originalMethod.isVarargs()) { |
128 |
int paramLength = parameters.length; |
108 |
int paramLength = parameters.length; |
Lines 130-137
Link Here
|
130 |
int argLength = arguments.length; |
110 |
int argLength = arguments.length; |
131 |
// process mandatory arguments |
111 |
// process mandatory arguments |
132 |
for (int i = 0; i < minArgLength; i++) { |
112 |
for (int i = 0; i < minArgLength; i++) { |
133 |
parameters[i].collectSubstitutes(scope, arguments[i], collectedSubstitutes, CONSTRAINT_EXTENDS); |
113 |
inferenceContext.argumentIndex = i; |
134 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
114 |
parameters[i].collectSubstitutes(scope, arguments[i], inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); |
|
|
115 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
135 |
} |
116 |
} |
136 |
// process optional arguments |
117 |
// process optional arguments |
137 |
if (minArgLength < argLength) { |
118 |
if (minArgLength < argLength) { |
Lines 153-209
Link Here
|
153 |
// eliminate one array dimension |
134 |
// eliminate one array dimension |
154 |
varargType = ((ArrayBinding)varargType).elementsType(); |
135 |
varargType = ((ArrayBinding)varargType).elementsType(); |
155 |
} |
136 |
} |
|
|
137 |
inferenceContext.argumentIndex = minArgLength; |
156 |
for (int i = minArgLength; i < argLength; i++) { |
138 |
for (int i = minArgLength; i < argLength; i++) { |
157 |
varargType.collectSubstitutes(scope, arguments[i], collectedSubstitutes, CONSTRAINT_EXTENDS); |
139 |
varargType.collectSubstitutes(scope, arguments[i], inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); |
158 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
140 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
159 |
} |
141 |
} |
160 |
} |
142 |
} |
161 |
} else { |
143 |
} else { |
162 |
int paramLength = parameters.length; |
144 |
int paramLength = parameters.length; |
163 |
for (int i = 0; i < paramLength; i++) { |
145 |
for (int i = 0; i < paramLength; i++) { |
164 |
parameters[i].collectSubstitutes(scope, arguments[i], collectedSubstitutes, CONSTRAINT_EXTENDS); |
146 |
inferenceContext.argumentIndex = i; |
165 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
147 |
parameters[i].collectSubstitutes(scope, arguments[i], inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); |
|
|
148 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
166 |
} |
149 |
} |
167 |
} |
150 |
} |
168 |
TypeVariableBinding[] originalVariables = originalMethod.typeVariables; |
151 |
if (inferenceContext.status == InferenceContext.RAW_SUBSTITUTION) { |
169 |
int varLength = originalVariables.length; |
|
|
170 |
substitutes = resolveSubstituteConstraints(scope, originalVariables , substitutes, false/*ignore Ti<:Uk*/, collectedSubstitutes); |
171 |
if (substitutes == null) |
172 |
return null; // incompatible |
173 |
if (substitutes.length == 0) { |
174 |
// raw generic method inferred |
152 |
// raw generic method inferred |
175 |
return scope.environment().createParameterizedGenericMethod(originalMethod, (RawTypeBinding)null); |
153 |
return scope.environment().createParameterizedGenericMethod(originalMethod, (RawTypeBinding)null); |
176 |
} |
154 |
} |
|
|
155 |
inferenceContext.argumentIndex = -1; // outside argument inference |
156 |
TypeVariableBinding[] originalVariables = originalMethod.typeVariables; |
157 |
if (!resolveSubstituteConstraints(scope, originalVariables , inferenceContext, false/*ignore Ti<:Uk*/)) |
158 |
return null; // impossible substitution |
159 |
|
177 |
// apply inferred variable substitutions - replacing unresolved variable with original ones in param method |
160 |
// apply inferred variable substitutions - replacing unresolved variable with original ones in param method |
178 |
TypeBinding[] resolvedSubstitutes = substitutes; |
161 |
TypeBinding[] inferredSustitutes = inferenceContext.substitutes; |
179 |
for (int i = 0; i < varLength; i++) { |
162 |
TypeBinding[] actualSubstitutes = inferredSustitutes; |
180 |
if (substitutes[i] == null) { |
163 |
for (int i = 0, varLength = originalVariables.length; i < varLength; i++) { |
181 |
if (resolvedSubstitutes == substitutes) { |
164 |
if (inferredSustitutes[i] == null) { |
182 |
System.arraycopy(substitutes, 0, resolvedSubstitutes = new TypeBinding[varLength], 0, i); // clone to replace null with original variable in param method |
165 |
if (actualSubstitutes == inferredSustitutes) { |
|
|
166 |
System.arraycopy(inferredSustitutes, 0, actualSubstitutes = new TypeBinding[varLength], 0, i); // clone to replace null with original variable in param method |
183 |
} |
167 |
} |
184 |
resolvedSubstitutes[i] = originalVariables[i]; |
168 |
actualSubstitutes[i] = originalVariables[i]; |
185 |
} else if (resolvedSubstitutes != substitutes) { |
169 |
} else if (actualSubstitutes != inferredSustitutes) { |
186 |
resolvedSubstitutes[i] = substitutes[i]; |
170 |
actualSubstitutes[i] = inferredSustitutes[i]; |
187 |
} |
171 |
} |
188 |
} |
172 |
} |
189 |
return scope.environment().createParameterizedGenericMethod(originalMethod, resolvedSubstitutes); |
173 |
ParameterizedGenericMethodBinding paramMethod = scope.environment().createParameterizedGenericMethod(originalMethod, actualSubstitutes); |
|
|
174 |
return paramMethod; |
190 |
} |
175 |
} |
191 |
|
176 |
|
192 |
private static TypeBinding[] resolveSubstituteConstraints(Scope scope, TypeVariableBinding[] typeVariables, TypeBinding[] substitutes, boolean considerEXTENDSConstraints, Map collectedSubstitutes) { |
177 |
private static boolean resolveSubstituteConstraints(Scope scope, TypeVariableBinding[] typeVariables, InferenceContext inferenceContext, boolean considerEXTENDSConstraints) { |
193 |
if (collectedSubstitutes.isEmpty()) { |
178 |
TypeBinding[] substitutes = inferenceContext.substitutes; |
194 |
// raw generic method inferred |
|
|
195 |
return Binding.NO_TYPES; // empty array |
196 |
} |
197 |
int varLength = typeVariables.length; |
179 |
int varLength = typeVariables.length; |
198 |
|
|
|
199 |
// check Tj=U constraints |
180 |
// check Tj=U constraints |
200 |
nextTypeParameter: |
181 |
nextTypeParameter: |
201 |
for (int i = 0; i < varLength; i++) { |
182 |
for (int i = 0; i < varLength; i++) { |
202 |
TypeVariableBinding current = typeVariables[i]; |
183 |
TypeVariableBinding current = typeVariables[i]; |
203 |
TypeBinding substitute = substitutes[i]; |
184 |
TypeBinding substitute = substitutes[i]; |
204 |
if (substitute != null) continue nextTypeParameter; // already inferred previously |
185 |
if (substitute != null) continue nextTypeParameter; // already inferred previously |
205 |
TypeBinding[][] variableSubstitutes = (TypeBinding[][]) collectedSubstitutes.get(current); |
186 |
TypeBinding [] equalSubstitutes = inferenceContext.getSubstitutes(current, TypeConstants.CONSTRAINT_EQUAL); |
206 |
TypeBinding [] equalSubstitutes = variableSubstitutes[CONSTRAINT_EQUAL]; |
|
|
207 |
if (equalSubstitutes != null) { |
187 |
if (equalSubstitutes != null) { |
208 |
nextConstraint: |
188 |
nextConstraint: |
209 |
for (int j = 0, equalLength = equalSubstitutes.length; j < equalLength; j++) { |
189 |
for (int j = 0, equalLength = equalSubstitutes.length; j < equalLength; j++) { |
Lines 234-266
Link Here
|
234 |
} |
214 |
} |
235 |
} |
215 |
} |
236 |
} |
216 |
} |
237 |
if (hasUnresolvedTypeArgument(substitutes)) { |
217 |
if (inferenceContext.hasUnresolvedTypeArgument()) { |
238 |
// check Tj>:U constraints |
218 |
// check Tj>:U constraints |
239 |
nextTypeParameter: |
219 |
nextTypeParameter: |
240 |
for (int i = 0; i < varLength; i++) { |
220 |
for (int i = 0; i < varLength; i++) { |
241 |
TypeVariableBinding current = typeVariables[i]; |
221 |
TypeVariableBinding current = typeVariables[i]; |
242 |
TypeBinding substitute = substitutes[i]; |
222 |
TypeBinding substitute = substitutes[i]; |
243 |
if (substitute != null) continue nextTypeParameter; // already inferred previously |
223 |
if (substitute != null) continue nextTypeParameter; // already inferred previously |
244 |
TypeBinding[][] variableSubstitutes = (TypeBinding[][]) collectedSubstitutes.get(current); |
224 |
TypeBinding [] bounds = inferenceContext.getSubstitutes(current, TypeConstants.CONSTRAINT_SUPER); |
245 |
TypeBinding [] bounds = variableSubstitutes[CONSTRAINT_SUPER]; |
|
|
246 |
if (bounds == null) continue nextTypeParameter; |
225 |
if (bounds == null) continue nextTypeParameter; |
247 |
TypeBinding mostSpecificSubstitute = scope.lowerUpperBound(bounds); |
226 |
TypeBinding mostSpecificSubstitute = scope.lowerUpperBound(bounds); |
248 |
if (mostSpecificSubstitute == null) |
227 |
if (mostSpecificSubstitute == null) { |
249 |
return null; // incompatible |
228 |
return false; // incompatible |
|
|
229 |
} |
250 |
if (mostSpecificSubstitute != TypeBinding.VOID) { |
230 |
if (mostSpecificSubstitute != TypeBinding.VOID) { |
251 |
substitutes[i] = mostSpecificSubstitute; |
231 |
substitutes[i] = mostSpecificSubstitute; |
252 |
} |
232 |
} |
253 |
} |
233 |
} |
254 |
} |
234 |
} |
255 |
if (considerEXTENDSConstraints && hasUnresolvedTypeArgument(substitutes)) { |
235 |
if (considerEXTENDSConstraints && inferenceContext.hasUnresolvedTypeArgument()) { |
256 |
// check Tj<:U constraints |
236 |
// check Tj<:U constraints |
257 |
nextTypeParameter: |
237 |
nextTypeParameter: |
258 |
for (int i = 0; i < varLength; i++) { |
238 |
for (int i = 0; i < varLength; i++) { |
259 |
TypeVariableBinding current = typeVariables[i]; |
239 |
TypeVariableBinding current = typeVariables[i]; |
260 |
TypeBinding substitute = substitutes[i]; |
240 |
TypeBinding substitute = substitutes[i]; |
261 |
if (substitute != null) continue nextTypeParameter; // already inferred previously |
241 |
if (substitute != null) continue nextTypeParameter; // already inferred previously |
262 |
TypeBinding[][] variableSubstitutes = (TypeBinding[][]) collectedSubstitutes.get(current); |
242 |
TypeBinding [] bounds = inferenceContext.getSubstitutes(current, TypeConstants.CONSTRAINT_EXTENDS); |
263 |
TypeBinding [] bounds = variableSubstitutes[CONSTRAINT_EXTENDS]; |
|
|
264 |
if (bounds == null) continue nextTypeParameter; |
243 |
if (bounds == null) continue nextTypeParameter; |
265 |
TypeBinding[] glb = Scope.greaterLowerBound(bounds); |
244 |
TypeBinding[] glb = Scope.greaterLowerBound(bounds); |
266 |
TypeBinding mostSpecificSubstitute = null; |
245 |
TypeBinding mostSpecificSubstitute = null; |
Lines 271-277
Link Here
|
271 |
} |
250 |
} |
272 |
} |
251 |
} |
273 |
} |
252 |
} |
274 |
return substitutes; |
253 |
return true; |
275 |
} |
254 |
} |
276 |
|
255 |
|
277 |
/** |
256 |
/** |
Lines 288-294
Link Here
|
288 |
} |
267 |
} |
289 |
this.isRaw = true; |
268 |
this.isRaw = true; |
290 |
this.tagBits = originalMethod.tagBits; |
269 |
this.tagBits = originalMethod.tagBits; |
291 |
this.isUnchecked = false; |
|
|
292 |
this.environment = environment; |
270 |
this.environment = environment; |
293 |
this.modifiers = originalMethod.modifiers; |
271 |
this.modifiers = originalMethod.modifiers; |
294 |
this.selector = originalMethod.selector; |
272 |
this.selector = originalMethod.selector; |
Lines 322-328
Link Here
|
322 |
this.typeArguments = typeArguments; |
300 |
this.typeArguments = typeArguments; |
323 |
this.isRaw = false; |
301 |
this.isRaw = false; |
324 |
this.tagBits = originalMethod.tagBits; |
302 |
this.tagBits = originalMethod.tagBits; |
325 |
this.isUnchecked = false; |
|
|
326 |
this.originalMethod = originalMethod; |
303 |
this.originalMethod = originalMethod; |
327 |
this.parameters = Scope.substitute(this, originalMethod.parameters); |
304 |
this.parameters = Scope.substitute(this, originalMethod.parameters); |
328 |
this.thrownExceptions = Scope.substitute(this, originalMethod.thrownExceptions); |
305 |
this.thrownExceptions = Scope.substitute(this, originalMethod.thrownExceptions); |
Lines 383-397
Link Here
|
383 |
* Given some type expectation, and type variable bounds, perform some inference. |
360 |
* Given some type expectation, and type variable bounds, perform some inference. |
384 |
* Returns true if still had unresolved type variable at the end of the operation |
361 |
* Returns true if still had unresolved type variable at the end of the operation |
385 |
*/ |
362 |
*/ |
386 |
private ParameterizedGenericMethodBinding inferFromExpectedType(Scope scope, TypeBinding expectedType, Map collectedSubstitutes, TypeBinding[] substitutes) { |
363 |
private ParameterizedGenericMethodBinding inferFromExpectedType(Scope scope, TypeBinding expectedType, InferenceContext inferenceContext) { |
387 |
TypeVariableBinding[] originalVariables = this.originalMethod.typeVariables; // immediate parent (could be a parameterized method) |
364 |
TypeVariableBinding[] originalVariables = this.originalMethod.typeVariables; // immediate parent (could be a parameterized method) |
388 |
int varLength = originalVariables.length; |
365 |
int varLength = originalVariables.length; |
389 |
|
366 |
|
390 |
computeSubstitutes: { |
367 |
computeSubstitutes: { |
391 |
// infer from expected return type |
368 |
// infer from expected return type |
392 |
if (expectedType != null) { |
369 |
if (expectedType != null) { |
393 |
this.returnType.collectSubstitutes(scope, expectedType, collectedSubstitutes, CONSTRAINT_SUPER); |
370 |
this.returnType.collectSubstitutes(scope, expectedType, inferenceContext, TypeConstants.CONSTRAINT_SUPER); |
394 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
371 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
395 |
} |
372 |
} |
396 |
// infer from bounds of type parameters |
373 |
// infer from bounds of type parameters |
397 |
for (int i = 0; i < varLength; i++) { |
374 |
for (int i = 0; i < varLength; i++) { |
Lines 400-430
Link Here
|
400 |
boolean argAlreadyInferred = argument != originalVariable; |
377 |
boolean argAlreadyInferred = argument != originalVariable; |
401 |
if (originalVariable.firstBound == originalVariable.superclass) { |
378 |
if (originalVariable.firstBound == originalVariable.superclass) { |
402 |
TypeBinding substitutedBound = Scope.substitute(this, originalVariable.superclass); |
379 |
TypeBinding substitutedBound = Scope.substitute(this, originalVariable.superclass); |
403 |
argument.collectSubstitutes(scope, substitutedBound, collectedSubstitutes, CONSTRAINT_SUPER); |
380 |
argument.collectSubstitutes(scope, substitutedBound, inferenceContext, TypeConstants.CONSTRAINT_SUPER); |
404 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
381 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
405 |
// JLS 15.12.2.8 claims reverse inference shouldn't occur, however it improves inference |
382 |
// JLS 15.12.2.8 claims reverse inference shouldn't occur, however it improves inference |
406 |
// e.g. given: <E extends Object, S extends Collection<E>> S test1(S param) |
383 |
// e.g. given: <E extends Object, S extends Collection<E>> S test1(S param) |
407 |
// invocation: test1(new Vector<String>()) will infer: S=Vector<String> and with code below: E=String |
384 |
// invocation: test1(new Vector<String>()) will infer: S=Vector<String> and with code below: E=String |
408 |
if (argAlreadyInferred) { |
385 |
if (argAlreadyInferred) { |
409 |
substitutedBound.collectSubstitutes(scope, argument, collectedSubstitutes, CONSTRAINT_EXTENDS); |
386 |
substitutedBound.collectSubstitutes(scope, argument, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); |
410 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
387 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
411 |
} |
388 |
} |
412 |
} |
389 |
} |
413 |
for (int j = 0, max = originalVariable.superInterfaces.length; j < max; j++) { |
390 |
for (int j = 0, max = originalVariable.superInterfaces.length; j < max; j++) { |
414 |
TypeBinding substitutedBound = Scope.substitute(this, originalVariable.superInterfaces[j]); |
391 |
TypeBinding substitutedBound = Scope.substitute(this, originalVariable.superInterfaces[j]); |
415 |
argument.collectSubstitutes(scope, substitutedBound, collectedSubstitutes, CONSTRAINT_SUPER); |
392 |
argument.collectSubstitutes(scope, substitutedBound, inferenceContext, TypeConstants.CONSTRAINT_SUPER); |
416 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
393 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
417 |
// JLS 15.12.2.8 claims reverse inference shouldn't occur, however it improves inference |
394 |
// JLS 15.12.2.8 claims reverse inference shouldn't occur, however it improves inference |
418 |
if (argAlreadyInferred) { |
395 |
if (argAlreadyInferred) { |
419 |
substitutedBound.collectSubstitutes(scope, argument, collectedSubstitutes, CONSTRAINT_EXTENDS); |
396 |
substitutedBound.collectSubstitutes(scope, argument, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS); |
420 |
if (collectedSubstitutes.get(TypeBinding.VOID) != null) return null; // impossible substitution |
397 |
if (inferenceContext.status == InferenceContext.FAILED) return null; // impossible substitution |
421 |
} |
398 |
} |
422 |
} |
399 |
} |
423 |
} |
400 |
} |
424 |
substitutes = resolveSubstituteConstraints(scope, originalVariables, substitutes, true/*consider Ti<:Uk*/, collectedSubstitutes); |
401 |
if (inferenceContext.status == InferenceContext.RAW_SUBSTITUTION) { |
425 |
if (substitutes == null) |
|
|
426 |
return null; // incompatible |
427 |
if (substitutes.length == 0) { |
428 |
// raw generic method inferred |
402 |
// raw generic method inferred |
429 |
this.isRaw = true; |
403 |
this.isRaw = true; |
430 |
this.isUnchecked = false; |
404 |
this.isUnchecked = false; |
Lines 432-443
Link Here
|
432 |
this.typeArguments[i] = originalVariables[i].upperBound(); |
406 |
this.typeArguments[i] = originalVariables[i].upperBound(); |
433 |
} |
407 |
} |
434 |
break computeSubstitutes; |
408 |
break computeSubstitutes; |
435 |
} |
409 |
} |
|
|
410 |
if (!resolveSubstituteConstraints(scope, originalVariables, inferenceContext, true/*consider Ti<:Uk*/)) |
411 |
return null; // incompatible |
436 |
// this.typeArguments = substitutes; - no op since side effects got performed during #resolveSubstituteConstraints |
412 |
// this.typeArguments = substitutes; - no op since side effects got performed during #resolveSubstituteConstraints |
437 |
for (int i = 0; i < varLength; i++) { |
413 |
for (int i = 0; i < varLength; i++) { |
438 |
TypeBinding substitute = substitutes[i]; |
414 |
TypeBinding substitute = inferenceContext.substitutes[i]; |
439 |
if (substitute != null) { |
415 |
if (substitute != null) { |
440 |
this.typeArguments[i] = substitutes[i]; |
416 |
this.typeArguments[i] = inferenceContext.substitutes[i]; |
441 |
} else { |
417 |
} else { |
442 |
// remaining unresolved variable are considered to be Object (or their bound actually) |
418 |
// remaining unresolved variable are considered to be Object (or their bound actually) |
443 |
this.typeArguments[i] = originalVariables[i].upperBound(); |
419 |
this.typeArguments[i] = originalVariables[i].upperBound(); |