Skip to content

Commit 6ca93cf

Browse files
committed
Add regression test for #11441 (assert on UnionType)
1 parent 31b55ac commit 6ca93cf

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug11441;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo {
8+
public function getParam(): ?string {
9+
return 'foo';
10+
}
11+
12+
/** @phpstan-assert !null $this->getParam() */
13+
public function checkNotNull(): void {
14+
if ($this->getParam() === null) {
15+
throw new \Exception();
16+
}
17+
}
18+
}
19+
20+
class Bar {
21+
public function getParam(): ?int {
22+
return 1;
23+
}
24+
25+
/** @phpstan-assert !null $this->getParam() */
26+
public function checkNotNull(): void {
27+
if ($this->getParam() === null) {
28+
throw new \Exception();
29+
}
30+
}
31+
}
32+
33+
function test(Foo|Bar $obj): void {
34+
assertType('int|string|null', $obj->getParam());
35+
36+
$obj->checkNotNull();
37+
38+
assertType('int|string', $obj->getParam());
39+
}

0 commit comments

Comments
 (0)