Skip to content

Commit 8156b17

Browse files
committed
Fix false positives about uninitialized readonly properties
1 parent b6a0b86 commit 8156b17

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Node/ClassPropertiesNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ private function getMethodsCalledFromConstructor(
353353
continue;
354354
}
355355

356+
if ($callScope->isInAnonymousFunction() && $callScope->getParentScope() !== null) {
357+
$callScope = $callScope->getParentScope();
358+
}
359+
356360
$methodName = $methodCallNode->name->toString();
357361
if (array_key_exists($methodName, $initializedProperties)) {
358362
foreach ($this->getInitializedProperties($callScope, $initializedProperties[$inMethod->getName()] ?? $initialInitializedProperties) as $propertyName => $isInitialized) {

tests/PHPStan/Rules/Properties/data/bug-10048.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php // lint >= 8.1
22

33
namespace Bug10048;
44

0 commit comments

Comments
 (0)