Skip to content

Commit 3ee8006

Browse files
phpstan-botclaude
andcommitted
Add INF test cases to bug-11054 regression test
Adds test coverage for INF (as opposed to NAN) in array constant comparisons. Unlike NAN, INF === INF is true in PHP, so type narrowing correctly eliminates the type after the first comparison. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cf401ab commit 3ee8006

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,13 @@ public function testPossiblyImpureTip(): void
11631163

11641164
public function testBug11054(): void
11651165
{
1166-
$this->analyse([__DIR__ . '/data/bug-11054.php'], []);
1166+
$this->analyse([__DIR__ . '/data/bug-11054.php'], [
1167+
[
1168+
'Strict comparison using === between mixed and array{INF} will always evaluate to false.',
1169+
47,
1170+
'Type array{INF} has already been eliminated from mixed.',
1171+
],
1172+
]);
11671173
}
11681174

11691175
}

tests/PHPStan/Rules/Comparison/data/bug-11054.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,26 @@ public static function convertEncoding (
3333
}
3434
}
3535

36+
class InfTest {
37+
public const DEF_VALUE = [INF];
38+
public const NO_VALUE = [INF];
39+
40+
/** @param mixed $v */
41+
public static function test($v): void
42+
{
43+
if ($v === self::DEF_VALUE) { // no error expected
44+
return;
45+
}
46+
47+
if ($v === self::NO_VALUE) {} // error expected - INF === INF is true, so narrowing is correct
48+
}
49+
}
50+
3651
class SimpleTest {
3752
/** @param mixed $v */
3853
public static function test($v): void
3954
{
4055
if ($v === [NAN]) {} // no error expected
56+
if ($v === [INF]) {} // no error expected
4157
}
4258
}

0 commit comments

Comments
 (0)