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

+ operator over array<int, int> is giving me mixed value #6261

Closed
VincentLanglet opened this issue Aug 8, 2021 · 2 comments · Fixed by #6272
Closed

+ operator over array<int, int> is giving me mixed value #6261

VincentLanglet opened this issue Aug 8, 2021 · 2 comments · Fixed by #6272
Labels

Comments

@VincentLanglet
Copy link
Contributor

I simplified my code to https://psalm.dev/r/1c3274bd0a
In my real case, I'm adding another array.

I don't understand why the value is considered as possibly mixed.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/1c3274bd0a
<?php

final class Token
{
    public const ONE = [
        16 => 16,
        21 => 21,
    ];

    public const TWO = [
        17 => 17,
        22 => 22,
    ];

    public const THREE = [
        18 => 18,
        23 => 23,
    ];

    public const RESULT = self::ONE + self::TWO + self::THREE;
    
    /**
     * @param int|int[] $bar
     * @return int|int[]
     */
    public function foo($bar) {
        return $bar;
    }
    
    public function test(): void {
        $this->foo(self::RESULT);
    }
}
Psalm output (using commit 3fb9e1c):

INFO: MixedArgumentTypeCoercion - 31:20 - Argument 1 of Token::foo expects array<array-key, int>|int, parent type array{16: 16, 17: 17, 18: 18|mixed, 21: 21, 22: 22, 23: 23|mixed} provided

@weirdan
Copy link
Collaborator

weirdan commented Aug 8, 2021

Funny thing that it works for (any) two arrays, but not for three.

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

Successfully merging a pull request may close this issue.

3 participants