Skip to content

Commit a97e9d9

Browse files
committed
Improve loose comparison on array type
1 parent 5a94e38 commit a97e9d9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Type/ArrayType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ public function isConstantValue(): TrinaryLogic
249249

250250
public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
251251
{
252+
if ($type->isInteger()->yes()) {
253+
return new ConstantBooleanType(false);
254+
}
255+
252256
return new BooleanType();
253257
}
254258

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,17 @@ public function sayConstUnion(
701701
/**
702702
* @param uppercase-string $upper
703703
* @param lowercase-string $lower
704+
* @param non-empty-array $nonEmptyArr
705+
* @param int<10, 20> $intRange
704706
*/
705707
public function sayIntersection(
706708
string $upper,
707709
string $lower,
708710
string $s,
711+
array $nonEmptyArr,
712+
array $arr,
713+
int $i,
714+
int $intRange,
709715
): void
710716
{
711717
assertType('bool', '' == $upper);
@@ -731,7 +737,11 @@ public function sayIntersection(
731737
assertType('bool', strtoupper($s) == $lower); // should be false
732738
assertType('bool', strtolower($s) == $lower);
733739
assertType('bool', $lower == $upper); // should be false
734-
}
735740

741+
assertType('false', $arr == $i);
742+
assertType('false', $nonEmptyArr == $i);
743+
assertType('false', $arr == $intRange);
744+
assertType('false', $nonEmptyArr == $intRange);
745+
}
736746

737747
}

0 commit comments

Comments
 (0)