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 31, 2023
1 parent bebce06 commit 103e7b3
Show file tree
Hide file tree
Showing 2 changed files with 14 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 (isset($storage->methods['__construct']) && $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
9 changes: 9 additions & 0 deletions tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,15 @@ public function setFoo() : void {
'assertions' => [],
'ignored_issues' => ['PropertyNotSetInConstructor'],
],
'unitializedPropertySuppressPropertyNotSetInAbstractConstructor' => [
'code' => '<?php
abstract class A {
/** @readonly */
public string $s;
abstract public function __construct(string $s);
}',
],
'setTKeyedArrayPropertyType' => [
'code' => '<?php
class Foo {
Expand Down

0 comments on commit 103e7b3

Please sign in to comment.