Skip to content

Fix GH-15375: nested "yield from" skips items after valid()/next()#22640

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-15375-nested-yield-from
Open

Fix GH-15375: nested "yield from" skips items after valid()/next()#22640
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-15375-nested-yield-from

Conversation

@iliaal

@iliaal iliaal commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Nested yield from drops the inner generator's current value on the second and later delegations when it was primed via valid()/next(). The ZEND_GENERATOR_DO_INIT guard in zend_generator_resume() reads the flag on orig_generator, but in a nested chain the fresh delegation is established by the middle generator, whose flag it never checks. Track and check the delegating generator instead.

Fixes #15375

The DO_INIT guard in zend_generator_resume() that avoids re-advancing an
already-primed delegate read the flag on orig_generator, but in a nested
"yield from" chain the fresh delegation is established by a middle generator
rather than the outermost consumer. Track the delegating generator through
the resume loop and check its DO_INIT, so a primed inner generator reached
through two "yield from" levels yields its current value once instead of
skipping it.

Fixes phpGH-15375
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant