vimeo / psalm

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

`MixedArgumentTypeCoercion` when try to use defined array type with ... #11073

Open Tigrov opened 1 month ago

Tigrov commented 1 month ago

When trying to define array type with known key-values and unknown using ... or more specific ...<string, mixed>

/**
 * @psalm-type Info = array{
 *     key?: string|null,
 *     ...<string, mixed>
 * }
 */

It shows an error MixedArgumentTypeCoercion with description that known key-values have also mixed values, although it is not explicitly defined in the type.

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

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

I found these snippets:

https://psalm.dev/r/3bc76124cc ```php * } */ class A { /** * @psalm-param Info $info */ public function init(array $info = []): void { // Access to the array values $info['key'] ?? ''; $this->init2($info); } /** * @psalm-param Info $info */ public function init2(array $info = []): void { // Some code here } } ``` ``` Psalm output (using commit 16b24bd): INFO: MixedArgumentTypeCoercion - 19:22 - Argument 1 of A::init2 expects array{key?: null|string, ...}, but parent type array{key?: mixed|null|string, ...} provided ```