From 1cc534759f1cbb5ae05f2e3057d0f487a572aa12 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 24 Jan 2025 14:18:59 +0100 Subject: [PATCH] Do not check abstract properties as uninitialized --- src/Node/ClassPropertiesNode.php | 3 +++ .../Rules/Properties/UninitializedPropertyRuleTest.php | 10 ++++++++++ tests/PHPStan/Rules/Properties/data/bug-12336.php | 7 +++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/PHPStan/Rules/Properties/data/bug-12336.php diff --git a/src/Node/ClassPropertiesNode.php b/src/Node/ClassPropertiesNode.php index c22ec65c29..e1f299a60e 100644 --- a/src/Node/ClassPropertiesNode.php +++ b/src/Node/ClassPropertiesNode.php @@ -118,6 +118,9 @@ public function getUninitializedProperties( if ($property->isStatic()) { continue; } + if ($property->isAbstract()) { + continue; + } if ($property->getNativeType() === null) { continue; } diff --git a/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php index 340c1331d9..d434683e6a 100644 --- a/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php +++ b/tests/PHPStan/Rules/Properties/UninitializedPropertyRuleTest.php @@ -7,6 +7,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use function strpos; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -216,4 +217,13 @@ public function testRedeclareReadonlyProperties(): void ]); } + public function testBug12336(): void + { + if (PHP_VERSION_ID < 80400) { + $this->markTestSkipped('Test requires PHP 8.4.'); + } + + $this->analyse([__DIR__ . '/data/bug-12336.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/bug-12336.php b/tests/PHPStan/Rules/Properties/data/bug-12336.php new file mode 100644 index 0000000000..5e7380d9ce --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-12336.php @@ -0,0 +1,7 @@ += 8.4 + +namespace Bug12336; + +abstract class ListItem { + abstract public int $item { get; } +}