vimeo / psalm

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

InvalidDocblock when declare psalm-type using array shape syntax with `is` key #9548

Open alies-dev opened 1 year ago

alies-dev commented 1 year ago

https://psalm.dev/r/005f4a160c

It seems like is is sort of special key name, if I rename it to anything else - it works without any issues

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

I found these snippets:

https://psalm.dev/r/005f4a160c ```php } * @psalm-param PermissionsArray $permissions */ function can(string $ability, array $permissions): bool { return $permissions['is'][$ability] ?? false; } ``` ``` Psalm output (using commit 0af503a): ERROR: InvalidDocblock - 7:1 - Cannot process colon without parent ERROR: UndefinedDocblockClass - 5:17 - Docblock-defined class, interface or enum named PermissionsArray does not exist ERROR: MismatchingDocblockParamType - 5:17 - Parameter $permissions has wrong type 'PermissionsArray', should be 'array' INFO: MixedInferredReturnType - 7:52 - Could not verify return type 'bool' for can ```
ygottschalk commented 1 year ago

Here is a workaround: https://psalm.dev/r/2d7eaece0a

Just quote the key

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

I found these snippets:

https://psalm.dev/r/2d7eaece0a ```php } * @psalm-param PermissionsArray $permissions */ function can(string $ability, array $permissions): bool { return $permissions['is'][$ability] ?? false; } ``` ``` Psalm output (using commit 0af503a): No issues! ```