diff --git a/src/Application/ChangedNodeScopeRefresher.php b/src/Application/ChangedNodeScopeRefresher.php index 6a85cc6245..51322fba22 100644 --- a/src/Application/ChangedNodeScopeRefresher.php +++ b/src/Application/ChangedNodeScopeRefresher.php @@ -50,7 +50,9 @@ public function refresh(Node $node, string $filePath, ?MutatingScope $mutatingSc throw new ShouldNotHappenException($errorMessage); } - NodeAttributeReIndexer::reIndexNodeAttributes($node); + // reindex stmt_key already covered on StmtKeyNodeVisitor on next processNodes() + // so set flag $reIndexStmtKey to false to avoid double loop + NodeAttributeReIndexer::reIndexNodeAttributes($node, false); $stmts = $this->resolveStmts($node); $this->phpStanNodeScopeResolver->processNodes($stmts, $filePath, $mutatingScope); diff --git a/src/Application/NodeAttributeReIndexer.php b/src/Application/NodeAttributeReIndexer.php index 9e1c92f8ce..d8dda74d46 100644 --- a/src/Application/NodeAttributeReIndexer.php +++ b/src/Application/NodeAttributeReIndexer.php @@ -45,9 +45,11 @@ public static function reIndexStmtKeyNodeAttributes(Node $node): ?Node return $node; } - public static function reIndexNodeAttributes(Node $node): ?Node + public static function reIndexNodeAttributes(Node $node, bool $reIndexStmtKey = true): ?Node { - self::reIndexStmtKeyNodeAttributes($node); + if ($reIndexStmtKey) { + self::reIndexStmtKeyNodeAttributes($node); + } if ($node instanceof If_) { $node->elseifs = array_values($node->elseifs);