psalm icon indicating copy to clipboard operation
psalm copied to clipboard

False-positive `MixedArgument` (assignment in `if` clause)

Open gharlan opened this issue 10 months ago • 1 comments

https://psalm.dev/r/fe8e19a6dc

In else branch $pos is always int.

gharlan avatar Apr 07 '24 11:04 gharlan

I found these snippets:

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

function foo(?string $foo): ?string {
    if (null === $foo || false === $pos = strrpos($foo, '.')) {
        // do something
    } else {
        $foo = substr($foo, 0, $pos);
    }
    
    return $foo;
}
Psalm output (using commit ef3b018):

INFO: MixedArgument - 7:32 - Argument 3 of substr cannot be mixed, expecting int|null

psalm-github-bot[bot] avatar Apr 07 '24 11:04 psalm-github-bot[bot]