vimeo / psalm

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

Psalm is not appreciate `array_pop()` for multidimensional arrays #7376

Open vjik opened 2 years ago

vjik commented 2 years ago

Example: https://psalm.dev/r/50ec899b62

For simple array is OK: https://psalm.dev/r/f3d91c28a4

psalm-github-bot[bot] commented 2 years ago

I found these snippets:

https://psalm.dev/r/50ec899b62 ```php for $data[0] is never empty ```
https://psalm.dev/r/f3d91c28a4 ```php
orklah commented 2 years ago

with some traces: https://psalm.dev/r/75d92955eb

psalm-github-bot[bot] commented 2 years ago

I found these snippets:

https://psalm.dev/r/75d92955eb ```php }> array_pop($data[0]); /** @psalm-trace $data */; // should be: array{0: array}> if (empty($data[0])) { throw new InvalidArgumentException(); } } ``` ``` Psalm output (using commit d52c3f0): INFO: Trace - 11:30 - $data: array{0: non-empty-array}> INFO: Trace - 13:30 - $data: array{0: non-empty-array}> ERROR: DocblockTypeContradiction - 15:9 - Docblock-defined type non-empty-array for $data[0] is never empty ```
vjik commented 1 year ago

Any news?