vimeo / psalm

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

properties-of<Class> not compatible with array type #10993

Open juacala opened 3 months ago

juacala commented 3 months ago

I am getting that a constructor param that is typed as an array appears incompatible with properties-of<Class>. Seems like this should be compatible.

See: https://psalm.dev/r/706b992dc9

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

I found these snippets:

https://psalm.dev/r/706b992dc9 ```php $options options for the underlying engine * @return void */ public function __construct( string $host, string $port, string $user, string $password, array $options ) {} } class DBConnectInfoAsArray { /** * * @param string $dbType * @param string|null $linkID * @param bool $allowRead * @param bool $allowWrite * @param bool $separateLinks * @param string|null $database * @param properties-of $read, * @param properties-of $write */ public function __construct( string $dbType, string|null $linkID, bool $allowRead, bool $allowWrite, bool $separateLinks, string|null $database, array $read, array $write ) {} } ``` ``` Psalm output (using commit 16b24bd): ERROR: MismatchingDocblockParamType - 38:15 - Parameter $read has wrong type 'properties-of', should be 'array' ERROR: MismatchingDocblockParamType - 39:15 - Parameter $write has wrong type 'properties-of', should be 'array' ```
juacala commented 3 months ago

This appears to happen if you have no properties in the class you're referencing. This works:

https://psalm.dev/r/b9a3592c1d

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

I found these snippets:

https://psalm.dev/r/b9a3592c1d ```php $options options for the underlying engine * @return void */ public function __construct( public string $host, public string $port, public string $user, public string $password, public array $options ) {} } class DBConnectInfoAsArray { /** * * @param string $dbType * @param string|null $linkID * @param bool $allowRead * @param bool $allowWrite * @param bool $separateLinks * @param string|null $database * @param properties-of $read, * @param properties-of $write */ public function __construct( string $dbType, string|null $linkID, bool $allowRead, bool $allowWrite, bool $separateLinks, string|null $database, array $read, array $write ) {} } ``` ``` Psalm output (using commit 16b24bd): No issues! ```