diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 750a5ecb83..f077d955fc 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -422,9 +422,14 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType return new ConstantBooleanType(false); } - if ($this->isIterableAtLeastOnce()->no() && count($type->getConstantScalarValues()) === 1) { - // @phpstan-ignore equal.invalid, equal.notAllowed - return new ConstantBooleanType($type->getConstantScalarValues()[0] == []); // phpcs:ignore + if ($this->isIterableAtLeastOnce()->no()) { + if (count($type->getConstantScalarValues()) === 1) { + // @phpstan-ignore equal.invalid, equal.notAllowed + return new ConstantBooleanType($type->getConstantScalarValues()[0] == []); // phpcs:ignore + } + if ($type->isIterableAtLeastOnce()->yes()) { + return new ConstantBooleanType(false); + } } return new BooleanType(); diff --git a/tests/PHPStan/Analyser/nsrt/loose-comparisons.php b/tests/PHPStan/Analyser/nsrt/loose-comparisons.php index 721c3efd9b..921f66ad1a 100644 --- a/tests/PHPStan/Analyser/nsrt/loose-comparisons.php +++ b/tests/PHPStan/Analyser/nsrt/loose-comparisons.php @@ -761,7 +761,7 @@ public function sayIntersection( assertType('false', $nonEmptyArr == $i); assertType('false', $arr == $intRange); assertType('false', $nonEmptyArr == $intRange); - assertType('bool', $emptyArr == $nonEmptyArr); // should be false + assertType('false', $emptyArr == $nonEmptyArr); assertType('false', $nonEmptyArr == $emptyArr); assertType('bool', $arr == $nonEmptyArr); assertType('bool', $nonEmptyArr == $arr);