Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
var comparableRelation = new Map<string, RelationComparisonResult>();
var identityRelation = new Map<string, RelationComparisonResult>();
var enumRelation = new Map<string, RelationComparisonResult>();
var relationOverflowed = false;

// Extensions suggested for path imports when module resolution is node16 or higher.
// The first element of each tuple is the extension a file has.
Expand Down Expand Up @@ -22412,6 +22413,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
reportIncompatibleStack();
}
if (overflow) {
relationOverflowed = true;
// Record this relation as having failed such that we don't attempt the overflowing operation again.
const id = getRelationKey(source, target, /*intersectionState*/ IntersectionState.None, relation, /*ignoreConstraints*/ false);
relation.set(id, RelationComparisonResult.Failed | (relationCount <= 0 ? RelationComparisonResult.ComplexityOverflow : RelationComparisonResult.StackDepthOverflow));
Expand Down Expand Up @@ -36539,7 +36541,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const isJsxOpeningOrSelfClosingElement = isJsxOpeningLikeElement(node);
const isJsxOpenFragment = isJsxOpeningFragment(node);
const isInstanceof = node.kind === SyntaxKind.BinaryExpression;
const reportErrors = !isInferencePartiallyBlocked && !candidatesOutArray;
let reportErrors = !isInferencePartiallyBlocked && !candidatesOutArray;

// The following variables are captured and modified by calls to chooseOverload.
// If overload resolution or type argument inference fails, we want to report the
Expand Down Expand Up @@ -36612,6 +36614,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// If we are in signature help, a trailing comma indicates that we intend to provide another argument,
// so we will only accept overloads with arity at least 1 higher than the current number of provided arguments.
const signatureHelpTrailingComma = !!(checkMode & CheckMode.IsForSignatureHelp) && node.kind === SyntaxKind.CallExpression && node.arguments.hasTrailingComma;
const saveRelationOverflowed = relationOverflowed;
relationOverflowed = false;

// Section 4.12.1:
// if the candidate list contains one or more signatures for which the type of each argument
Expand All @@ -36629,6 +36633,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (!result) {
result = chooseOverload(candidates, assignableRelation, isSingleNonGenericCandidate, signatureHelpTrailingComma);
}
// Disable error reporting if relation overflowed during the overload resolution given the oveflow error was already reported.
// By attempting to report the error below the overflow could not happen again (given some of the caches would already be populated)
// and the compiler would crash with "No error for last overload signature".
reportErrors &&= !relationOverflowed;
relationOverflowed = saveRelationOverflowed;

const links = getNodeLinks(node);
if (links.resolvedSignature !== resolvingSignature && !candidatesOutArray) {
// There are 2 situations in which it's good to preemptively return the cached result here:
Expand Down