Skip to content

Commit ef4fde5

Browse files
committed
Add regression test for #12434
Union of two non-empty-list wrappers around distinct array shapes: non-empty-list<array{name: BackedEnum}>|non-empty-list<array{name: string}>. With @phpstan-assert-if-true narrowing to one variant, the else branch previously stayed as the full union; now it correctly narrows to the remaining variant. Closes phpstan/phpstan#12434
1 parent d31ee52 commit ef4fde5

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12434;
4+
5+
use BackedEnum;
6+
use function PHPStan\Testing\assertType;
7+
8+
class HelloWorld
9+
{
10+
11+
/**
12+
* @param non-empty-list<array{name: BackedEnum}>|non-empty-list<array{name: string}> $values
13+
*/
14+
public function sayHello(array $values): void
15+
{
16+
assertType('non-empty-list<array{name: BackedEnum}>|non-empty-list<array{name: string}>', $values);
17+
if ($this->testShape($values)) {
18+
assertType('non-empty-list<array{name: string}>', $values);
19+
} else {
20+
assertType('non-empty-list<array{name: BackedEnum}>', $values);
21+
}
22+
}
23+
24+
/**
25+
* @param non-empty-list<array{name: BackedEnum}>|non-empty-list<array{name: string}> $values
26+
* @phpstan-assert-if-true non-empty-list<array{name: string}> $values
27+
*/
28+
private function testShape(array $values): bool
29+
{
30+
return true;
31+
}
32+
33+
}

0 commit comments

Comments
 (0)