Skip to content

Commit

Permalink
Remove old hack that skipped parameters during inference; this was re…
Browse files Browse the repository at this point in the history
…lavent when the non-inferrable type was an any
  • Loading branch information
jakebailey committed Jul 14, 2022
1 parent 28bc9d6 commit 9e831ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 53 deletions.
19 changes: 8 additions & 11 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23049,21 +23049,18 @@ namespace ts {
const sourceLen = sourceSignatures.length;
const targetLen = targetSignatures.length;
const len = sourceLen < targetLen ? sourceLen : targetLen;
const skipParameters = !!(getObjectFlags(source) & ObjectFlags.NonInferrableType);
for (let i = 0; i < len; i++) {
inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]), skipParameters);
inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getErasedSignature(targetSignatures[targetLen - len + i]));
}
}

function inferFromSignature(source: Signature, target: Signature, skipParameters: boolean) {
if (!skipParameters) {
const saveBivariant = bivariant;
const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown;
// Once we descend into a bivariant signature we remain bivariant for all nested inferences
bivariant = bivariant || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.MethodSignature || kind === SyntaxKind.Constructor;
applyToParameterTypes(source, target, inferFromContravariantTypes);
bivariant = saveBivariant;
}
function inferFromSignature(source: Signature, target: Signature) {
const saveBivariant = bivariant;
const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown;
// Once we descend into a bivariant signature we remain bivariant for all nested inferences
bivariant = bivariant || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.MethodSignature || kind === SyntaxKind.Constructor;
applyToParameterTypes(source, target, inferFromContravariantTypes);
bivariant = saveBivariant;
applyToReturnTypes(source, target, inferFromTypes);
}

Expand Down
38 changes: 0 additions & 38 deletions tests/baselines/reference/nonInferrableTypePropagation2.errors.txt

This file was deleted.

8 changes: 4 additions & 4 deletions tests/baselines/reference/nonInferrableTypePropagation2.types
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ const x = pipe(es, filter(exists((n) => n > 0)))
>es : Either<string, number>[]
>filter(exists((n) => n > 0)) : (as: readonly Either<string, number>[]) => readonly Either<string, number>[]
>filter : { <A, B extends A>(refinement: Refinement<A, B>): (as: readonly A[]) => readonly B[]; <A>(predicate: Predicate<A>): <B extends A>(bs: readonly B[]) => readonly B[]; <A>(predicate: Predicate<A>): (as: readonly A[]) => readonly A[]; }
>exists((n) => n > 0) : <E>(ma: Either<E, unknown>) => boolean
>exists((n) => n > 0) : <E>(ma: Either<E, number>) => boolean
>exists : <A>(predicate: Predicate<A>) => <E>(ma: Either<E, A>) => boolean
>(n) => n > 0 : (n: unknown) => boolean
>n : unknown
>(n) => n > 0 : (n: number) => boolean
>n : number
>n > 0 : boolean
>n : unknown
>n : number
>0 : 0

0 comments on commit 9e831ec

Please sign in to comment.