Skip to content

Avoid cached expression recursion during loop narrowing - #64013

Closed
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-stack-overflow-narrowing
Closed

Avoid cached expression recursion during loop narrowing#64013
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-stack-overflow-narrowing

Conversation

Copilot AI commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Control flow analysis could stack overflow when narrowing a loop variable assigned from an as const object that references the same variable. The cached expression path discarded in-progress loop-flow state, preventing recursive loop analysis from terminating.

Example:

let lastCandidate: Candidate | null = null;
while (true) {
    const candidate: Candidate = {
        mode: "a",
        output: lastCandidate,
    } as const;
    lastCandidate = candidate;
}
  • Flow analysis

    • Avoids expression caching while loop flow analysis is already in progress.
    • Preserves the active loop-flow stack so recursive references can use incomplete loop types instead of restarting uncached analysis.
  • Tests

    • Adds a compiler regression test for the as const loop assignment crash.
    • Updates affected loop narrowing baselines where precise types are now retained instead of circular any errors.

Copilot AI and others added 2 commits August 25, 2026 19:40
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix stack overflow in narrowing as const object Avoid cached expression recursion during loop narrowing Aug 25, 2026
@jakebailey
Jake Bailey (jakebailey) deleted the copilot/fix-stack-overflow-narrowing branch August 25, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack overflow narrowing as const object assigned to loop variable it references

2 participants