vimeo / psalm

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

Psalm treat an array as `array<array-key, mixed>` if it does not know the key type #11059

Open kafkiansky opened 1 month ago

kafkiansky commented 1 month ago

Hi. I'm writing a plugin for my protobuf serialization library. I decided to do a tight integration with static analysis tools and let users specify types directly in the phpdoc: @param int32 $id. Now I was able to teach psalm through the plugin to understand such types, but not for an array. If the array key contains a type known to psalm, for example array<string, int32>, there is no problem, but not when the key is unknown, for example array<int32, string>, - in this case psalm thinks that there is array<array-key, mixed>. What can be done in this case?

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

Hey @kafkiansky, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.