Skip to content

Commit 7a3f001

Browse files
committed
Fix ConstantArray loose comparison
1 parent 9e3d1d3 commit 7a3f001

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Type/Constant/ConstantArrayType.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,14 @@ public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
422422
return new ConstantBooleanType(false);
423423
}
424424

425-
if ($this->isIterableAtLeastOnce()->no() && count($type->getConstantScalarValues()) === 1) {
426-
// @phpstan-ignore equal.invalid, equal.notAllowed
427-
return new ConstantBooleanType($type->getConstantScalarValues()[0] == []); // phpcs:ignore
425+
if ($this->isIterableAtLeastOnce()->no()) {
426+
if (count($type->getConstantScalarValues()) === 1) {
427+
// @phpstan-ignore equal.invalid, equal.notAllowed
428+
return new ConstantBooleanType($type->getConstantScalarValues()[0] == []); // phpcs:ignore
429+
}
430+
if ($type->isIterableAtLeastOnce()->yes()) {
431+
return new ConstantBooleanType(false);
432+
}
428433
}
429434

430435
return new BooleanType();

tests/PHPStan/Analyser/nsrt/loose-comparisons.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ public function sayIntersection(
761761
assertType('false', $nonEmptyArr == $i);
762762
assertType('false', $arr == $intRange);
763763
assertType('false', $nonEmptyArr == $intRange);
764-
assertType('bool', $emptyArr == $nonEmptyArr); // should be false
764+
assertType('false', $emptyArr == $nonEmptyArr);
765765
assertType('false', $nonEmptyArr == $emptyArr);
766766
assertType('bool', $arr == $nonEmptyArr);
767767
assertType('bool', $nonEmptyArr == $arr);

0 commit comments

Comments
 (0)