Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tigrov opened this issue Aug 14, 2024 · 1 comment
Open

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

Tigrov opened this issue Aug 14, 2024 · 1 comment

Comments

@Tigrov
Copy link

Tigrov commented Aug 14, 2024

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

Copy link

I found these snippets:

https://psalm.dev/r/3bc76124cc
<?php
/**
 * @psalm-type Info = array{
 *     key?: string|null,
 *     ...<string, mixed>
 * }
 */

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, ...<string, mixed>}, but parent type array{key?: mixed|null|string, ...<string, mixed>} provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant