Skip to content

Commit defd353

Browse files
committed
Include inferences from preceding outer arguments
1 parent 0ca87b3 commit defd353

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20403,10 +20403,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2040320403

2040420404
/**
2040520405
* Return a type mapper that combines the context's return mapper with a mapper that erases any additional type parameters
20406-
* to their constraints.
20406+
* to their inferences at the time of creation.
2040720407
*/
2040820408
function createOuterReturnMapper(context: InferenceContext) {
20409-
return mergeTypeMappers(context.returnMapper, createInferenceContext(map(context.inferences, i => i.typeParameter), context.signature, context.flags, context.compareTypes).mapper);
20409+
return context.outerReturnMapper ??= mergeTypeMappers(context.returnMapper, cloneInferenceContext(context).mapper);
2041020410
}
2041120411

2041220412
function combineTypeMappers(mapper1: TypeMapper | undefined, mapper2: TypeMapper): TypeMapper {
@@ -35550,9 +35550,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3555035550
// the source type uses the outer context's return mapper (which excludes inferences made from
3555135551
// outer arguments), and (b) we don't want any further inferences going into this context.
3555235552
// We use `createOuterReturnMapper` to ensure that all occurrences of outer type parameters are
35553-
// replaced with either inferences produced from the outer return type or constraints of those
35554-
// type parameters. This protects against circular inferences, i.e. avoiding situations where
35555-
// inferences reference type parameters for which the inferences are being made.
35553+
// replaced with inferences produced from the outer return type or preceding outer arguments.
35554+
// This protects against circular inferences, i.e. avoiding situations where inferences reference
35555+
// type parameters for which the inferences are being made.
3555635556
const returnContext = createInferenceContext(signature.typeParameters!, signature, context.flags);
3555735557
const returnSourceType = instantiateType(contextualType, outerContext && createOuterReturnMapper(outerContext));
3555835558
inferTypes(returnContext.inferences, returnSourceType, inferenceTargetType);

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,6 +7114,7 @@ export interface InferenceContext {
71147114
mapper: TypeMapper; // Mapper that fixes inferences
71157115
nonFixingMapper: TypeMapper; // Mapper that doesn't fix inferences
71167116
returnMapper?: TypeMapper; // Type mapper for inferences from return types (if any)
7117+
outerReturnMapper?: TypeMapper; // Type mapper for inferences from return types of outer function (if any)
71177118
inferredTypeParameters?: readonly TypeParameter[]; // Inferred type parameters for function result
71187119
intraExpressionInferenceSites?: IntraExpressionInferenceSite[];
71197120
}

0 commit comments

Comments
 (0)