psalm icon indicating copy to clipboard operation
psalm copied to clipboard

False positive RedundantConditionGivenDocblockType when combining mixed and null-coalescing operator

Open blackwolf12333 opened this issue 2 years ago • 1 comments

https://psalm.dev/r/1d89182ec6

I think this should not infer that the string length is always 0. With mixed as type I don't think you can know that it always reduces to 0.

blackwolf12333 avatar Aug 11 '22 14:08 blackwolf12333

I found these snippets:

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

/** @var array<array-key, mixed> $array */
$array = [];

$iLen = strlen($array['offset'] ?? '');

if ($iLen === 0) {
}
Psalm output (using commit ffc8c80):

INFO: MixedArgument - 6:16 - Argument 1 of strlen cannot be ''|mixed, expecting string

ERROR: RedundantConditionGivenDocblockType - 8:5 - Docblock-defined type 0 for $iLen is always =int(0)

psalm-github-bot[bot] avatar Aug 11 '22 14:08 psalm-github-bot[bot]