From ba0c207ec32ca2c7e84d529b3272394b11663423 Mon Sep 17 00:00:00 2001 From: Pascal CESCON - Amoifr Date: Sun, 25 Oct 2026 09:23:05 +0100 Subject: [PATCH] Add regression test for #12820 Refs https://github.com/phpstan/phpstan/issues/12820 --- .../Rules/Methods/CallMethodsRuleTest.php | 9 ++++ .../PHPStan/Rules/Methods/data/bug-12820.php | 49 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-12820.php diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index e03a97fc739..b3bee1cfe9a 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -4560,6 +4560,15 @@ public function testBug15251(): void $this->analyse([__DIR__ . '/data/bug-15251.php'], []); } + #[RequiresPhp('>= 8.0.0')] + public function testBug12820(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->analyse([__DIR__ . '/data/bug-12820.php'], []); + } + #[RequiresPhp('>= 8.1.0')] public function testClassConstantWildcardArguments(): void { diff --git a/tests/PHPStan/Rules/Methods/data/bug-12820.php b/tests/PHPStan/Rules/Methods/data/bug-12820.php new file mode 100644 index 00000000000..f55271a7ebb --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-12820.php @@ -0,0 +1,49 @@ += 8.0 + +declare(strict_types = 1); + +namespace Bug12820; + +class A +{ + + public function a(): void + { + } + +} + +class B +{ + +} + +/** @template-covariant T of A|B = A|B */ +interface FooInterface +{ + + /** + * @phpstan-assert-if-true static $this + */ + public function isA(): bool; + + /** @return T */ + public function get(): A|B; + +} + +/** + * @template-covariant T of A|B = A|B + * @implements FooInterface + */ +abstract class Foo implements FooInterface +{ + + public function other(): void + { + if ($this->isA()) { + $this->get()->a(); + } + } + +}