Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-5207b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug5207b;

use function PHPStan\Testing\assertType;

abstract class HelloWorld {
abstract public function getChild(): ?HelloWorld;

public function sayHello(): void {
$foo = null !== $this->getChild()->getChild();
if ($foo) {
assertType('Bug5207b\HelloWorld|null', $this->getChild()); // could be Bug5207b\HelloWorld
assertType('Bug5207b\HelloWorld', $this->getChild()->getChild());
assertType('Bug5207b\HelloWorld|null', $this->getChild()->getChild()->getChild());
}
}

public function sayFoo(): void {
$foo = null !== $this?->getChild()?->getChild();
if ($foo) {
assertType('Bug5207b\HelloWorld', $this->getChild());
assertType('Bug5207b\HelloWorld', $this->getChild()->getChild());
assertType('Bug5207b\HelloWorld|null', $this->getChild()->getChild()->getChild());
}
}

public function sayBar(): void {
$foo = null !== $this?->getChild()->getChild();
if ($foo) {
assertType('Bug5207b\HelloWorld', $this->getChild());
assertType('Bug5207b\HelloWorld', $this->getChild()->getChild());
assertType('Bug5207b\HelloWorld|null', $this->getChild()->getChild()->getChild());
}
}
}
Loading