Skip to content

Commit

Permalink
PropertyNotSetInConstructor should not report for abstract constructors
Browse files Browse the repository at this point in the history
since they do not have any code

Fix #9830
  • Loading branch information
kkmuffme committed May 30, 2023
1 parent bebce06 commit 4a24bf2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,11 @@ private function checkPropertyInitialization(
return;
}

// abstract constructors do not have any code, therefore cannot set any properties either
if ($storage->methods['__construct']->abstract) {
return;
}

$fq_class_name = $class_context->self ?: $this->fq_class_name;
$fq_class_name_lc = strtolower($fq_class_name);

Expand Down
11 changes: 11 additions & 0 deletions tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,17 @@ public function setFoo() : void {
'assertions' => [],
'ignored_issues' => ['PropertyNotSetInConstructor'],
],
'unitializedPropertySuppressPropertyNotSetInAbstractConstructor' => [
'code' => '<?php
abstract class A {
/** @readonly */
public string $s;
abstract public function __construct(string $s);
}',
'assertions' => [],
'ignored_issues' => ['PropertyNotSetInConstructor'],
],
'setTKeyedArrayPropertyType' => [
'code' => '<?php
class Foo {
Expand Down

0 comments on commit 4a24bf2

Please sign in to comment.