Skip to content

Commit 217459a

Browse files
committed
Drop the null check the destructured merge() result makes dead
merge() returns array{Type, null}|array{null, Type}, so once $a is null the destructured $b is a Type. Also regenerates the AssignHandler declarations for the new helper and adds the issue-bot reproducer of #12487, which the destructuring narrowing fixes. Amp-Thread-ID: https://ampcode.com/threads/T-01a22b9b-2b0a-7521-a915-75eebb3a519c
1 parent 46db55e commit 217459a

3 files changed

Lines changed: 242 additions & 209 deletions

File tree

‎src/Type/Combinator/SubsumptionUnionRule.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ public function apply(array $types, array $normalizedGroups): array
156156
}
157157
continue;
158158
}
159-
if ($b === null) {
160-
continue;
161-
}
162159

163160
$isNew = $b !== $types[$j];
164161
$types[$j] = $b;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12487;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/** @return array{true, int} | array{false, string} */
8+
function foo(): array
9+
{
10+
return (rand() & 1) !== 0 ? [true, 42] : [false, 'bar'];
11+
}
12+
13+
function doFoo(): void
14+
{
15+
[$isInteger, $value] = foo();
16+
if ($isInteger) {
17+
assertType('int', $value);
18+
} else {
19+
assertType('string', $value);
20+
}
21+
22+
$ret = foo();
23+
assertType('array{false, string}|array{true, int}', $ret);
24+
if ($ret[0]) {
25+
assertType('int', $ret[1]);
26+
} else {
27+
assertType('string', $ret[1]);
28+
}
29+
}

0 commit comments

Comments
 (0)