Bug #70965 [NEW]: `yield from` with a common iterator primes too much
From: srice at fb dot com
Operating system: Linux
PHP version: 7.0.0RC7
Package: Scripting Engine problem
Bug Type: Bug
Bug description:yield from with a common iterator primes too much
Description:
------------
When two separate generator instances yield from a common iterator the
second element of the iterator gets skipped. There is a test case to
keep this from happening with a common shared generator (and the fix
keeps track of which generator is priming or not) but it doesnt work
with iterators. See the sample script below (which is mostly just a
small change to the multiple_yield_from_on_same_generator test that
already exists).
Test script:
---------------
<?php
function it() {
yield from [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
}
function bar($g) {
yield from $g;
}
$gen = it();
$gens[] = bar($gen);
$gens[] = bar($gen);
do {
foreach($gens as $g) {
var_dump($g->current());
$gen->next();
}
} while ($gen->valid());
Expected result:
----------------
int(1)
int(2)
int(3)
int(4)
int(5)
int(6)
int(7)
int(8)
int(9)
int(10)
Actual result:
--------------
int(1)
int(3)
int(4)
int(5)
int(6)
int(7)
int(8)
int(9)
int(10)
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=70965&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70965&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70965&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70965&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70965&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70965&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70965&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70965&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70965&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70965&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70965&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70965&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70965&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70965&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70965&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70965&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70965&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70965&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70965&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70965&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70965&r=mysqlcfg
Thread (7 messages)
- srice at fb dot com