mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #2225 - iterator_to_array can return a list
This commit is contained in:
parent
0556f28a9f
commit
1a1b3a10a9
@ -63,6 +63,14 @@ class IteratorToArrayReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionRe
|
||||
}
|
||||
|
||||
if ($value_type) {
|
||||
if (isset($call_args[1]->value->inferredType)
|
||||
&& ((string) $call_args[1]->value->inferredType === 'false')
|
||||
) {
|
||||
return new Type\Union([
|
||||
new Type\Atomic\TList($value_type),
|
||||
]);
|
||||
}
|
||||
|
||||
return new Type\Union([
|
||||
new Type\Atomic\TArray([
|
||||
$key_type
|
||||
|
@ -991,6 +991,21 @@ class FunctionCallTest extends TestCase
|
||||
'$a' => 'array<int, string>',
|
||||
],
|
||||
],
|
||||
'iteratorToArrayWithGetIteratorReturningList' => [
|
||||
'<?php
|
||||
class C implements IteratorAggregate {
|
||||
/**
|
||||
* @return Traversable<int,string>
|
||||
*/
|
||||
public function getIterator() {
|
||||
yield 1 => "1";
|
||||
}
|
||||
}
|
||||
$a = iterator_to_array(new C, false);',
|
||||
'assertions' => [
|
||||
'$a' => 'list<string>',
|
||||
],
|
||||
],
|
||||
'arrayColumnInference' => [
|
||||
'<?php
|
||||
function makeMixedArray(): array { return []; }
|
||||
|
Loading…
Reference in New Issue
Block a user