Repository navigation
A yield inside an expression is an error, and a yield's value is undefined - #621
Merged
Merged
Conversation
…fined
mlirGen(YieldExpression) returned success with no value, so an expression
around a yield was silently dropped: `const t = ("a" + i) + (yield 1)` left t
unwritten and the program crashed reading it. A value computed before the
yield in the same expression would be an SSA value of the turn that returned,
gone when the generator resumes at the state label.
A yield now gives undefined (made after the label; next() takes no argument
yet) where nothing is computed before it: `yield x;`, `const v = yield x;` and
`v = yield x;`. The statement marks those yields (the AST has no parent links);
any other yield is a compile error, and so is using the value of yield*.
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.
mlirGen(YieldExpression)returned success with no value, so any expression around a yield was silently dropped.const t = ("a" + i) + (yield 1)never wrotet, and the program crashed reading it (every memory model, gc included). A value computed before the yield in the same expression would also be an SSA value of the turn that returned, gone when the generator resumes at the state label.undefined, made after the label (next()takes no argument yet). This applies where nothing is computed before the yield:yield x;,const v = yield x;andv = yield x;(withvan identifier).SupportedYieldScope), because the AST has no parent links. Compiler-made yields sit in expression statements, so they count as statement-level.a yield inside an expression is not supported ... assign the yield to a variable first. Using the value ofyield*is also an error, since it still gives nothing back.Tests:
00generator_yield_value.ts(compile + jit, in the corpus, so it runs under rc/none too).yield-in-expression/{binary,call_argument,yield_star_value}.ts, checked for the error under gc/rc/none.Full
ctest -C Release -j 16: 100% passed, 0 failed out of 4782.Not covered here: a variable declaration whose initializer fails with no diagnostic still declares an uninitialized variable. That silent-failure gap is general and has nothing to do with yield.
🤖 Generated with Claude Code