vimeo / psalm

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

Intersection types must be all objects when attempting to expand an object-like-array template #5459

Open M1ke opened 3 years ago

M1ke commented 3 years ago

Originally posted by @M1ke in https://github.com/vimeo/psalm/discussions/5457

https://psalm.dev/r/1c3999b349

Whilst trying to work out how to denote the type of an expanding object-like-array I ran into this issue (see Psalm bot below).

Having posted it as a discussion it was suggested that Psalm should likely handle this situation, so here we are!

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

I found these snippets:

https://psalm.dev/r/1c3999b349 ```php 1]; $data = array_merge($default, $data); return $data; } ``` ``` Psalm output (using commit a96645d): ERROR: InvalidDocblock - 8:1 - Intersection types must be all objects or all object-like arrays, Psalm\Type\Atomic\TKeyedArray provided in docblock for appendUser INFO: MixedArgumentTypeCoercion - 10:33 - Argument 2 of array_merge expects array, parent type T:fn-appenduser as mixed provided ```
azjezz commented 3 years ago

I think the error correct in the example provided since T is mixed, however, the error still stand:

https://psalm.dev/r/3d6101b3fb

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

I found these snippets:

https://psalm.dev/r/3d6101b3fb ```php 1]; $data = array_merge($default, $data); return $data; } ``` ``` Psalm output (using commit efa9b13): ERROR: InvalidDocblock - 8:1 - Intersection types must be all objects or all object-like arrays, Psalm\Type\Atomic\TKeyedArray provided in docblock for appendUser ```