Skip to content

Commit

Permalink
Merge pull request #9844 from kkmuffme/property-no-set-in-constructor…
Browse files Browse the repository at this point in the history
…-abstract-false-positive

PropertyNotSetInConstructor should not report for abstract constructors
  • Loading branch information
orklah committed Jun 1, 2023
2 parents a762b6c + 103e7b3 commit 75baaf7
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
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
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 75baaf7

Please sign in to comment.