Repository navigation
compiler: drop with objects at a loop's continue landing - #721
Merged
Merged
Conversation
A continue that leaves a with body through a finally keeps the with objects enclosing the try pushed, so the finally body still sees them. Nothing dropped them afterwards: the continue completion resumed at the loop's continue target with those objects still pushed. The next iteration's lookups inside a with then resolved through them. Each loop now truncates the frame's with objects to the loop's own depth at its continue landing, as it already did at its break landing. Normal fall-through reaches the landing with nothing extra pushed, so the truncate is a no-op there. It is only emitted when the loop body contains a with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes the FIXME left by #719.
Problem: a
continuethat leaves awithbody through afinallykeeps the with objects enclosing the try pushed, so the finally body can still see them. Nothing dropped them afterwards, so they stayed in scope for the next iteration. A lookup inside a laterwithin that iteration then resolved through the leaked object:Fix: each loop (
while,for,do-while,for-in,for-of) now emitsOpTruncateWithat its continue landing, as it already does at its break landing. Normal fall-through reaches the landing with nothing extra pushed, so the truncate is a no-op there. It is only emitted when the loop body contains awith.Testing
tests/scripts/with_continue_through_finally.ts.TestScriptsis green.language+built-ins, vs main): no change. No test262 test covers this case.🤖 Generated with Claude Code