Skip to content

Fix stack overflow in getExplicitTypeOfSymbol() for self-referential for...of#4655

Open
johnfav03 wants to merge 1 commit into
microsoft:mainfrom
johnfav03:repro/g-mermaid-flow-overflow
Open

Fix stack overflow in getExplicitTypeOfSymbol() for self-referential for...of#4655
johnfav03 wants to merge 1 commit into
microsoft:mainfrom
johnfav03:repro/g-mermaid-flow-overflow

Conversation

@johnfav03

Copy link
Copy Markdown
Contributor

Fixes an issue uncovered in #4532 (comment); with a self-referential type whose iterable is the loop variable itself (for (const a of a)), getExplicitTypeOfSymbol() faces unbound recursion. This PR fixes that by keeping a set in the checker keyed by the symbol, which guards the function with AddIfAbsent and otherwise removes the symbol from the set at the end of the function.

Copilot AI review requested due to automatic review settings July 16, 2026 16:58

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

Fixes an infinite recursion/stack overflow in the Go checker’s getExplicitTypeOfSymbol() when analyzing self-referential for...of constructs (e.g. for (const a of a)), by adding a per-checker recursion guard keyed by symbol and validating the behavior with a new compiler regression test and baselines.

Changes:

  • Added a Checker.resolvingExplicitTypeOfSymbol set and used it to short-circuit recursive re-entry in getExplicitTypeOfSymbol().
  • Added a regression compiler test covering for (const a of a) with subsequent usage patterns that previously triggered unbounded recursion.
  • Checked in new reference baselines for diagnostics, emit, symbols, and types for the new test.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/checker/checker.go Adds resolvingExplicitTypeOfSymbol to Checker state for recursion guarding.
internal/checker/flow.go Uses the new set to prevent unbounded recursion in getExplicitTypeOfSymbol().
testdata/tests/cases/compiler/forOfSelfReferentialDottedName.ts New regression test reproducing the self-referential for...of scenario.
testdata/baselines/reference/compiler/forOfSelfReferentialDottedName.errors.txt Expected diagnostics baseline for the new regression test.
testdata/baselines/reference/compiler/forOfSelfReferentialDottedName.js Expected JS emit baseline for the new regression test.
testdata/baselines/reference/compiler/forOfSelfReferentialDottedName.symbols Expected symbols baseline for the new regression test.
testdata/baselines/reference/compiler/forOfSelfReferentialDottedName.types Expected types baseline for the new regression test.

@johnfav03
johnfav03 requested a review from iisaduan July 16, 2026 17:27
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.

2 participants