From 13cdd23141c89688beaa40e0711d0c6d33ee7af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 8 Feb 2026 21:52:40 +0100 Subject: [PATCH] Don't attempt to report signature candidate errors on relation overflows --- src/compiler/checker.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8fa3c4fce2a4a..9605aaca21474 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2388,6 +2388,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var comparableRelation = new Map(); var identityRelation = new Map(); var enumRelation = new Map(); + 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. @@ -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)); @@ -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 @@ -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 @@ -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: