vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 659 forks source link

Traversable|array confused with iterable #8824

Open othercorey opened 1 year ago

othercorey commented 1 year ago

https://psalm.dev/r/00b98216f3

It looks like Traversable|array is collapsed to iterable but then compared against the original Traversable|array type.

psalm-github-bot[bot] commented 1 year ago

I found these snippets:

https://psalm.dev/r/00b98216f3 ```php ', should be 'Traversable|array' ```
weirdan commented 1 year ago

Traversable|array is precisely iterable; we should just collapse the native type too.

mpdude commented 3 months ago

Does this issue report also cover the following case?

https://psalm.dev/r/8521cc0da1

I thought that might be the case when iterator_to_array() is internally defined with an argument of Traversable|array, and Psalm does not recognize this to be equivalent to iterable?

psalm-github-bot[bot] commented 3 months ago

I found these snippets:

https://psalm.dev/r/8521cc0da1 ```php */ function x(): iterable { return ["hello" => "world"]; } iterator_to_array(x()); ``` ``` Psalm output (using commit 16b24bd): ERROR: InvalidArgument - 10:19 - Argument 1 of iterator_to_array expects Traversable|array, but iterable provided ```