Bug #70904 [Asn->Csd]: `yield from` incorrectly marks valid generator as finished

From: Date: Tue, 24 Nov 2015 22:44:13 +0000
Subject: Bug #70904 [Asn->Csd]: `yield from` incorrectly marks valid generator as finished
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197403@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70904&edit=1 ID: 70904 Updated by: bwoebi@php.net Reported by: srice at fb dot com Summary: yield from incorrectly marks valid generator as finished -Status: Assigned +Status: Closed Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 7.0.0RC7 Assigned To: bwoebi Block user comment: N Private report: N New Comment: Automatic comment on behalf of bobwei9@hotmail.com Revision: http://git.php.net/?p=php-src.git;a=commit;h=80d9dcafe0ee130c52ed2eb33b302e02b93620d4 Log: Fixed bug #70904 (yield from incorrectly marks valid generator as finished) Previous Comments: ------------------------------------------------------------------------ [2015-11-24 20:56:05] requinix@php.net Related To: Bug #70965 ------------------------------------------------------------------------ [2015-11-13 01:00:30] srice at fb dot com Description: ------------ The current implementation of the valid method doesnt properly take into account the possibility that the inner generator could be executed outside of the context of the outer generator. In this case, its saying that the outer generator isnt valid because the inner generator isnt valid, but in fact the outer generator still has more to execute. Test script: --------------- <?php function g1() { yield 1; yield 2; } function g2($g1) { yield from $g1; echo "!\n"; yield 3; } $g1 = g1(); $g2 = g2($g1); while ($g2->valid()) { var_dump($g2->current()); $g1->next(); } Expected result: ---------------- I would expect the following: int(1) int(2) NULL NULL NULL ...(infinite loop) I say this because g2 got primed to the yield from statement, so it should be returning for current whatever g1 is returning for current. For a finished generator, this would be NULL. Actual result: -------------- int(1) int(2) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70904&edit=1

« previous php.bugs (#197403) next »