Skip to content

Commit df169d6

Browse files
ondrejmirtesclaude
andcommitted
Add regression tests for #9455 and #5207
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3749be6 commit df169d6

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Bug5207;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
abstract class HelloWorld
8+
{
9+
10+
abstract public function getChild(): ?HelloWorld;
11+
12+
public function sayHello(): HelloWorld
13+
{
14+
$foo = null !== $this->getChild();
15+
16+
if ($foo) {
17+
assertType(HelloWorld::class, $this->getChild());
18+
return $this->getChild();
19+
}
20+
21+
throw new \Exception();
22+
}
23+
24+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Bug9455;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class A {
8+
public function __construct(private int $id) {}
9+
10+
public function getId(): int
11+
{
12+
return $this->id;
13+
}
14+
}
15+
16+
class B {
17+
public function __construct(private int $id, private ?A $a = null) {}
18+
19+
public function getId(): int
20+
{
21+
return $this->id;
22+
}
23+
24+
public function getA(): ?A
25+
{
26+
return $this->a;
27+
}
28+
}
29+
30+
class HelloWorld
31+
{
32+
33+
public function testFails(B $b): void
34+
{
35+
$hasA = $b->getA() !== null;
36+
37+
if ($hasA) {
38+
assertType(A::class, $b->getA());
39+
echo $b->getA()->getId();
40+
}
41+
}
42+
43+
public function testSucceeds(B $b): void
44+
{
45+
if ($b->getA() !== null) {
46+
assertType(A::class, $b->getA());
47+
echo $b->getA()->getId();
48+
}
49+
}
50+
51+
}

0 commit comments

Comments
 (0)