Skip to content

Commit 81b60c6

Browse files
committed
add test for fixed bug 8555
It was fixed by fixing union(int, int<null, -1>, int<1, null>) = int.
1 parent 81b7706 commit 81b60c6

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,10 @@ public function testBug5365(): void
433433
$this->analyse([__DIR__ . '/data/bug-5365.php'], []);
434434
}
435435

436+
public function testBug8555(): void
437+
{
438+
$this->treatPhpDocTypesAsCertain = true;
439+
$this->analyse([__DIR__ . '/data/bug-8555.php'], []);
440+
}
441+
436442
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bug8555;
4+
5+
/**
6+
* @return array<string, int|null>
7+
*/
8+
function test(int $first, int $second): array
9+
{
10+
return [
11+
'test' => $first && $second ? $first : null,
12+
'test2' => $first && $second ? $first : null,
13+
];
14+
}

tests/PHPStan/Type/TypeCombinatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,15 @@ public function dataUnion(): iterable
15771577
IntegerRangeType::class,
15781578
'int<4, 81>',
15791579
],
1580+
[
1581+
[
1582+
new IntegerType(),
1583+
IntegerRangeType::fromInterval(null, -1),
1584+
IntegerRangeType::fromInterval(1, null),
1585+
],
1586+
IntegerType::class,
1587+
'int',
1588+
],
15801589
[
15811590
[
15821591
IntegerRangeType::fromInterval(1, 3),

0 commit comments

Comments
 (0)