Fix stack overflow in getExplicitTypeOfSymbol() for self-referential for...of#4655
Open
johnfav03 wants to merge 1 commit into
Open
Fix stack overflow in getExplicitTypeOfSymbol() for self-referential for...of#4655johnfav03 wants to merge 1 commit into
getExplicitTypeOfSymbol() for self-referential for...of#4655johnfav03 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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.resolvingExplicitTypeOfSymbolset and used it to short-circuit recursive re-entry ingetExplicitTypeOfSymbol(). - 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withAddIfAbsentand otherwise removes the symbol from the set at the end of the function.