vimeo / psalm

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

Incomplete message: of type mixed cannot be assigned to #7216

Open kamil-tekiela opened 2 years ago

kamil-tekiela commented 2 years ago

https://psalm.dev/r/6c5e5a3c16

I think there are some pieces of it missing.

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

I found these snippets:

https://psalm.dev/r/6c5e5a3c16 ```php $column) { $metadata[$i]->name = $column; } ``` ``` Psalm output (using commit 18c790e): INFO: MixedAssignment - 3:1 - Unable to determine the type that $metadata is being assigned to ERROR: UndefinedGlobalVariable - 4:10 - Cannot find referenced variable $query_data in global scope INFO: MixedArrayAccess - 4:10 - Cannot access array value on mixed variable $query_data INFO: MixedAssignment - 4:36 - Unable to determine the type that $i is being assigned to INFO: MixedAssignment - 4:42 - Unable to determine the type that $column is being assigned to INFO: MixedArrayAccess - 5:3 - Cannot access array value on mixed variable $metadata INFO: MixedArrayOffset - 5:3 - Cannot access value on variable $metadata using mixed offset INFO: MixedPropertyAssignment - 5:3 - of type mixed cannot be assigned to ```
orklah commented 2 years ago

Full message should probably be $metadata[$i]->name of type mixed cannot be assigned to but Psalm has difficulties identifying this kind of var id. Maybe the error should have a fallback instead to something like property name of WhateverClass of type mixed cannot be assigned to but it'll probably have to be duplicated in a lot of places