php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70904 `yield from` incorrectly marks valid generator as finished
Submitted: 2015-11-13 01:00 UTC Modified: 2015-11-13 17:12 UTC
From: srice at fb dot com Assigned: bwoebi (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.0RC7 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: srice at fb dot com
New email:
PHP Version: OS:

 

 [2015-11-13 01:00 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-13 01:55 UTC] laruence@php.net
-Assigned To: +Assigned To: nikic
 [2015-11-13 02:37 UTC] pollita@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2015-11-13 17:12 UTC] nikic@php.net
-Assigned To: nikic +Assigned To: bwoebi
 [2015-11-24 22:44 UTC] bwoebi@php.net
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)
 [2015-11-24 22:44 UTC] bwoebi@php.net
-Status: Assigned +Status: Closed
 [2015-11-24 22:44 UTC] bwoebi@php.net
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)
 [2016-07-20 11:35 UTC] davey@php.net
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)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC