Repository navigation
A yield in a finally block of a generator is an error, not skipped - #980
Merged
Merged
Conversation
TryOpLowering copies a try's finally for each way out of the try (the end of its body, the unwind, each
return/break/continue), each copy with the yield's resume label, and the generator's switch dispatches by
position: the copies shifted every label after them, so `try { yield 1; } finally { print("f"); yield 2; }`
gave 1, never 2, and resumed after the yield in another copy. Now an error at the yield (YieldInFinally),
as a yield in a catch is; a repeated resume label is an error in the lowering rather than a resume somewhere
else. Supporting it needs the finally lowered as straight code after the try (TSLANG 153, open).
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.
try { yield 1; } finally { print("f"); yield 2; }used to give 1, and then neither printed "f" nor yielded 2.Cause. TryOpLowering copies a try's
finallyonce for each way out of the try: the end of its body, the unwind, and eachreturn/break/continue. Every copy carries the yield's resume label. The generator's switch dispatches by position, so these copies shifted every label after them, and a resume landed after the yield in another copy.This PR.
YieldInFinally), as a yield in a catch already is. Resuming in the copy that runs while an exception unwinds is not possible.Supporting a yield in a finally needs that finally lowered as straight code after the try: a catch-all that keeps the exception, a record of how the try was left, and that way out taken again afterwards. This is recorded as open in TSLANG 153.
Tests.
diagnostic-location/generator_yield_in_finally.ts00generator_finally.ts: finally ordering around yields, and a generator declared in a finally (compile, jit, rc, own)Verified.
🤖 Generated with Claude Code