Skip to content

Don't ignore all generic self tail calls when collecting the return type of a function - #63999

Open
Mateusz Burzyński (Andarist) wants to merge 2 commits into
microsoft:mainfrom
Andarist:fix-63990
Open

Don't ignore all generic self tail calls when collecting the return type of a function#63999
Mateusz Burzyński (Andarist) wants to merge 2 commits into
microsoft:mainfrom
Andarist:fix-63990

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

fixes #63990 (a bug introduced with #53995 )

This PR avoids ignoring recursive self calls when the arguments list is not assignable to the parameter list of the signature declaration.

So this errors:

const f = <T>(a: T, p: number) => {
    if (!p) return a;
    return f(p, p - 1);
};

But this continues to work:

function h<T>(value: T, count: number) {
    if (!count) return value;
    return h(value, count - 1);
}

It also ignores generic calls with type argument lists because that can lead to other instantiations of the signature declaration.

Copilot AI balanced review requested due to automatic review settings August 25, 2026 09:53
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Aug 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Tightens generic recursive return-type inference so only same-instantiation tail calls are ignored.

Changes:

  • Checks recursive arguments against the current generic signature.
  • Adds regression coverage and generated baselines.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tsc/internal/checker/checker.go Refines recursive-call inference handling.
tsc/testdata/tests/cases/compiler/genericRecursiveFunctionReturn.ts Adds regression scenarios.
tsc/testdata/baselines/reference/compiler/genericRecursiveFunctionReturn.errors.txt Records expected diagnostics.
tsc/testdata/baselines/reference/compiler/genericRecursiveFunctionReturn.types Records inferred types.
tsc/testdata/baselines/reference/compiler/genericRecursiveFunctionReturn.symbols Records symbols.
tsc/testdata/baselines/reference/compiler/genericRecursiveFunctionReturn.js Records emitted JavaScript.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tsc/internal/checker/checker.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Generic recursive function infers incorrect return type

2 participants