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

False Positive: PhanPluginMixedKeyNoKey Should not mix array entries #4788

Closed
andrei-dascalu opened this issue Jul 8, 2023 · 1 comment
Closed

Comments

@andrei-dascalu
Copy link

version: 5.4.2

Given the following code

class SomeClass
{
    /**
     * @return array<string,string>
     */
    public function doSomething(): array
    {
        /** @var array<string,string> $response */
        $response = [
            'result' => 'result',
        ];

        return [
            ...$response,
            'another' => 'bar',
        ];
    }
}

results in

src/SomeClass.php:16 PhanPluginMixedKeyNoKey Should not mix array entries of the form [key => value,] with entries of the form [value,]

Seems that Phan doesn't correctly interpret the effects of the ... operator on <string,string> arrays ?

@Jimbolino
Copy link

This problem still exists in the latest version.

class SomeClass
{
    public function doSomething(): array
    {
        $response = [
            'result' => 'result',
        ];

        return [
            ...$response, // PhanPluginMixedKeyNoKey here
            'another' => 'bar',
        ];
    }
}
src/example.php:12 PhanPluginMixedKeyNoKey Should not mix array entries of the form [key => value,] with entries of the form [value,].

Probably the spread operator is not understood correctly

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

2 participants