Bug report
/**
* @template T
* @param iterable<mixed, T> $iterable
* @return ($iterable is list ? never : list<T>)
*/
function iteratorToList(iterable $iterable): array {
$list = [];
foreach ($iterable as $item) {
$list[] = $item;
}
return $list;
}
/**
* @return iterable<string, string>
*/
function getItems(): iterable {
yield 'a' => 'foo';
yield 'b' => 'bar';
}
$items = getItems();
$items = iteratorToList($items);
assert(count($items) === 2);
This code1 didn't raise any issues in PHPStan 1.11.4, but in 1.11.5 and later it outputs:
Call to function assert() with false will always evaluate to false.
and
Strict comparison using === between NEVER and 2 will always evaluate to false.
Interestingly, the issues go away when the output of the function is stored in a different variable than the input.
Code snippet that reproduces the problem
https://phpstan.org/r/4f0d2ce9-4b31-4885-8959-14f42f40a66f
Expected output
No issues.
Bug report
This code1 didn't raise any issues in PHPStan 1.11.4, but in 1.11.5 and later it outputs:
and
Interestingly, the issues go away when the output of the function is stored in a different variable than the input.
Code snippet that reproduces the problem
https://phpstan.org/r/4f0d2ce9-4b31-4885-8959-14f42f40a66f
Expected output
No issues.
Footnotes
We don't want this function to be called unnecessarily, so we have it to return
neverif the input is already definitely a list. ↩