psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Error at wrong place for redundant condition with ternary expression

Open M393 opened this issue 1 year ago • 1 comments

https://psalm.dev/r/7832c75a2a

Why is the error position at the else part of the ternary?

ERROR: RedundantCondition - 4:23 - Type list{'a'} for $a is always non-empty-countable

This error does not exist when an if-else is used instead of a ternary.

M393 avatar Oct 10 '24 15:10 M393

I found these snippets:

https://psalm.dev/r/7832c75a2a
<?php

$a = ['a'];
$_b = $a === [] ? 0 : 1;

if ($a === []) {
    $_c = 0;
} else {
    $_c = 1;
}
Psalm output (using commit dee5fe4):

ERROR: TypeDoesNotContainType - 4:7 - list{string} does not contain empty array

ERROR: TypeDoesNotContainType - 4:7 - Type list{'a'} for $a is always !non-empty-countable

ERROR: RedundantCondition - 4:23 - Type list{'a'} for $a is always non-empty-countable

ERROR: TypeDoesNotContainType - 6:5 - list{string} does not contain empty array

ERROR: TypeDoesNotContainType - 6:5 - Type list{'a'} for $a is always !non-empty-countable

psalm-github-bot[bot] avatar Oct 10 '24 15:10 psalm-github-bot[bot]