@@ -3505,6 +3505,7 @@ module ts {
3505
3505
return t => {
3506
3506
for (let i = 0; i < context.typeParameters.length; i++) {
3507
3507
if (t === context.typeParameters[i]) {
3508
+ context.inferences[i].isFixed = true;
3508
3509
return getInferredType(context, i);
3509
3510
}
3510
3511
}
@@ -4563,12 +4564,11 @@ module ts {
4563
4564
function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext {
4564
4565
let inferences: TypeInferences[] = [];
4565
4566
for (let unused of typeParameters) {
4566
- inferences.push({ primary: undefined, secondary: undefined });
4567
+ inferences.push({ primary: undefined, secondary: undefined, isFixed: false });
4567
4568
}
4568
4569
return {
4569
4570
typeParameters: typeParameters,
4570
4571
inferUnionTypes: inferUnionTypes,
4571
- inferenceCount: 0,
4572
4572
inferences: inferences,
4573
4573
inferredTypes: new Array(typeParameters.length),
4574
4574
};
@@ -4615,11 +4615,13 @@ module ts {
4615
4615
for (let i = 0; i < typeParameters.length; i++) {
4616
4616
if (target === typeParameters[i]) {
4617
4617
let inferences = context.inferences[i];
4618
- let candidates = inferiority ?
4619
- inferences.secondary || (inferences.secondary = []) :
4620
- inferences.primary || (inferences.primary = []);
4621
- if (!contains(candidates, source)) candidates.push(source);
4622
- break;
4618
+ if (!inferences.isFixed) {
4619
+ let candidates = inferiority ?
4620
+ inferences.secondary || (inferences.secondary = []) :
4621
+ inferences.primary || (inferences.primary = []);
4622
+ if (!contains(candidates, source)) candidates.push(source);
4623
+ }
4624
+ return;
4623
4625
}
4624
4626
}
4625
4627
}
@@ -6336,11 +6338,15 @@ module ts {
6336
6338
return getSignatureInstantiation(signature, getInferredTypes(context));
6337
6339
}
6338
6340
6339
- function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[]) : InferenceContext {
6341
+ function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[], context : InferenceContext): void {
6340
6342
let typeParameters = signature.typeParameters;
6341
- let context = createInferenceContext(typeParameters, /*inferUnionTypes*/ false);
6342
6343
let inferenceMapper = createInferenceMapper(context);
6343
6344
6345
+ // Clear out all the inference results from the last time inferTypeArguments was called on this context
6346
+ for (let i = 0; i < typeParameters.length; i++) {
6347
+ context.inferredTypes[i] = undefined;
6348
+ }
6349
+
6344
6350
// We perform two passes over the arguments. In the first pass we infer from all arguments, but use
6345
6351
// wildcards for all context sensitive function expressions.
6346
6352
for (let i = 0; i < args.length; i++) {
@@ -6385,8 +6391,6 @@ module ts {
6385
6391
inferredTypes[i] = unknownType;
6386
6392
}
6387
6393
}
6388
-
6389
- return context;
6390
6394
}
6391
6395
6392
6396
function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean): boolean {
@@ -6620,15 +6624,17 @@ module ts {
6620
6624
return resolveErrorCall(node);
6621
6625
6622
6626
function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>) {
6623
- for (let current of candidates) {
6624
- if (!hasCorrectArity(node, args, current )) {
6627
+ for (let originalCandidate of candidates) {
6628
+ if (!hasCorrectArity(node, args, originalCandidate )) {
6625
6629
continue;
6626
6630
}
6627
-
6628
- let originalCandidate = current;
6629
- let inferenceResult: InferenceContext;
6631
+
6630
6632
let candidate: Signature;
6631
6633
let typeArgumentsAreValid: boolean;
6634
+ let inferenceContext = originalCandidate.typeParameters
6635
+ ? createInferenceContext(originalCandidate.typeParameters, /*inferUnionTypes*/ false)
6636
+ : undefined;
6637
+
6632
6638
while (true) {
6633
6639
candidate = originalCandidate;
6634
6640
if (candidate.typeParameters) {
@@ -6638,9 +6644,9 @@ module ts {
6638
6644
typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false)
6639
6645
}
6640
6646
else {
6641
- inferenceResult = inferTypeArguments(candidate, args, excludeArgument);
6642
- typeArgumentsAreValid = inferenceResult .failedTypeParameterIndex < 0;
6643
- typeArgumentTypes = inferenceResult .inferredTypes;
6647
+ inferTypeArguments(candidate, args, excludeArgument, inferenceContext );
6648
+ typeArgumentsAreValid = inferenceContext .failedTypeParameterIndex < 0;
6649
+ typeArgumentTypes = inferenceContext .inferredTypes;
6644
6650
}
6645
6651
if (!typeArgumentsAreValid) {
6646
6652
break;
@@ -6670,7 +6676,7 @@ module ts {
6670
6676
else {
6671
6677
candidateForTypeArgumentError = originalCandidate;
6672
6678
if (!typeArguments) {
6673
- resultOfFailedInference = inferenceResult ;
6679
+ resultOfFailedInference = inferenceContext ;
6674
6680
}
6675
6681
}
6676
6682
}
0 commit comments