vimeo / psalm

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

Checking if list object property is empty does not convert to non-empty-list #9766

Open M393 opened 1 year ago

M393 commented 1 year ago

~https://psalm.dev/r/d375837035~

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

I found these snippets:

https://psalm.dev/r/d375837035 ```php $l * @return non-empty-list|null */ function f(array $l): array { if ($l === []) { return null; } return $l; } ``` ``` Psalm output (using commit d4c5f85): ERROR: MismatchingDocblockReturnType - 5:12 - Docblock has incorrect return type 'non-empty-list|null', should be 'array' INFO: MixedInferredReturnType - 5:12 - Could not verify return type 'non-empty-list|null' for f ```
M393 commented 1 year ago

https://psalm.dev/r/4a67e451d8

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

I found these snippets:

https://psalm.dev/r/4a67e451d8 ```php } $o * @return non-empty-list|null */ function f(object $o): ?array { if ($o->l === []) { return null; } /** @psalm-trace $o $o->l*/ return $o->l; } ``` ``` Psalm output (using commit d4c5f85): INFO: MixedReturnStatement - 12:12 - Could not infer a return type INFO: Trace - 12:5 - $o: object{l:list} INFO: Trace - 12:5 - $o->l: mixed INFO: MixedInferredReturnType - 5:12 - Could not verify return type 'non-empty-list|null' for f ```