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

in_array and TypeDoesNotContainNull #6333

Closed
ar2r opened this issue Aug 18, 2021 · 3 comments · Fixed by #6419
Closed

in_array and TypeDoesNotContainNull #6333

ar2r opened this issue Aug 18, 2021 · 3 comments · Fixed by #6419

Comments

@ar2r
Copy link

ar2r commented Aug 18, 2021

Here is example:
https://psalm.dev/r/274c08c832

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/274c08c832
<?php

function a(): ?string{
    return null;
}

$id = 'abc';
$srcProductId = a();
$srcCardId = a();

if (in_array($id, [$srcProductId, $srcCardId], true)) {
    echo "ok";
}
Psalm output (using commit 9e1f7ad):

ERROR: TypeDoesNotContainNull - 11:5 - Cannot resolve types for $id - string does not contain null

@TysonAndre
Copy link
Contributor

https://psalm.dev/r/f60f99e23a is possibly related (RedundantCondition for exactly null)

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/f60f99e23a
<?php

function test(?string $x, string $y): void {
    if (in_array($x, [null, $y], true)) {
        if ($x === null) {
            echo "Saw null\n";
        }
        echo "Saw $x\n";
    }
}
Psalm output (using commit a655ca8):

ERROR: RedundantCondition - 5:13 - Type null for $x is always null

TysonAndre added a commit to TysonAndre/psalm that referenced this issue Sep 4, 2021
TysonAndre added a commit to TysonAndre/psalm that referenced this issue Sep 4, 2021
Modified approach to vimeo#6396 by orklah

Fixes vimeo#6333

Co-Authored-By: orklah <ronan_morin@hotmail.com>
TysonAndre added a commit to TysonAndre/psalm that referenced this issue Sep 4, 2021
Modified approach to vimeo#6396 by orklah

Fixes vimeo#6333

Co-Authored-By: orklah <ronan_morin@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants