diff --git a/src/Type/Constant/ConstantFloatType.php b/src/Type/Constant/ConstantFloatType.php index b0cafcdca37..aff555fcfac 100644 --- a/src/Type/Constant/ConstantFloatType.php +++ b/src/Type/Constant/ConstantFloatType.php @@ -99,6 +99,15 @@ public function toArrayKey(): Type return new ConstantIntegerType((int) $this->value); } + public function getFiniteTypes(): array + { + if (is_nan($this->value)) { + return []; + } + + return [$this]; + } + public function generalize(GeneralizePrecision $precision): Type { return new FloatType(); diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index 33f419c4873..f2f43732108 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -1161,4 +1161,15 @@ public function testPossiblyImpureTip(): void ]); } + public function testBug11054(): void + { + $this->analyse([__DIR__ . '/data/bug-11054.php'], [ + [ + 'Strict comparison using === between mixed and array{INF} will always evaluate to false.', + 47, + 'Type array{INF} has already been eliminated from mixed.', + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-11054.php b/tests/PHPStan/Rules/Comparison/data/bug-11054.php new file mode 100644 index 00000000000..269308185c5 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-11054.php @@ -0,0 +1,58 @@ +