psalm
psalm copied to clipboard
Error at wrong place for redundant condition with ternary expression
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.
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