Fix :Generator without yield rejecting scalar return (#10333) - #10339
Merged
Conversation
Stop treating declared :Generator alone as a generator function; only functions with yield in source or compiled opcodes become generators. Enforce object return types for non-generator callables so returning a scalar throws TypeError matching Zend. Co-authored-by: Cursor <cursoragent@cursor.com>
3 tasks
This was referenced Jun 20, 2026
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.
Summary
: Generatorfunction as a generator; only callables withyield/yield fromin source (AST marker) or compiled opcodes are generators (Language: Generator::getReturn() — return value from generator (Zend zend_generators.c parity) #3350 / Language: Generator::getReturn() on return-before-yield — must return value not Exception (Zend/zend_generators.c) #9007 preserved).function g(): Generator { return 1; }throwsTypeErrorat the call site, matching Zend/php-src.GeneratorYieldSourceMarkerAST pass so unreachable yield afterreturnstill marks the callable as a generator when php-cfg DCE removes the yield opcode.php-src reference:
Zend/zend_execute.c(return-type validation),Zend/zend_generators.c(generator creation requires yield in body)PHP implementation:
lib/Ast/GeneratorYieldSourceMarker.php,lib/Compiler.php,lib/VM.php,lib/VM/TypeCheck.phpVerification
Output:
Closes #10333
Made with Cursor