Skip to content

Fix :Generator without yield rejecting scalar return (#10333) - #10339

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-10333-generator-return-scalar
Jun 20, 2026
Merged

Fix :Generator without yield rejecting scalar return (#10333)#10339
PurHur merged 1 commit into
masterfrom
agent/issue-10333-generator-return-scalar

Conversation

@PurHur

@PurHur PurHur commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

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.php

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_generator_return_scalar.php 2>&1 | head -3
php bin/vm.php test/repro/maintainer_gap_generator_return_scalar.php 2>&1 | head -5
./vendor/bin/phpunit --filter "generator_get_return|generator_return_type_scalar"
'

Output:

PHP Fatal error:  Uncaught TypeError: g(): Return value must be of type Generator, int returned ...  # Zend
PHP Fatal error:  Uncaught TypeError: g(): Return value must be of type Generator, int returned ...  # VM
OK (10 tests, 10 assertions)

Closes #10333

Made with Cursor

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: Generator return type without yield accepts scalar — missing TypeError (Zend/zend_generators.c)

1 participant