Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
call $nodeCallback() after loop
Browse files Browse the repository at this point in the history
samsonasik committed Dec 21, 2024

Verified

This commit was signed with the committer’s verified signature.
mdonnalley Mike Donnalley
1 parent ea63923 commit 211a0fb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
@@ -309,6 +309,11 @@ public function processNodes(

$alreadyTerminated = true;
$nextStmts = $this->getNextUnreachableStatements(array_slice($nodes, $i + 1), true);

if ($nextStmts === []) {
continue;
}

$unreachableStatementNode = null;
foreach ($nextStmts as $nextStmt) {
if ($unreachableStatementNode instanceof UnreachableStatementNode) {
@@ -317,8 +322,9 @@ public function processNodes(
}

$unreachableStatementNode = new UnreachableStatementNode($nextStmt);
$nodeCallback($unreachableStatementNode, $scope);
}

$nodeCallback($unreachableStatementNode, $scope);
}
}

@@ -407,6 +413,10 @@ public function processStmtNodes(
$alreadyTerminated = true;
$nextStmts = $this->getNextUnreachableStatements(array_slice($stmts, $i + 1), $parentNode instanceof Node\Stmt\Namespace_);

if ($nextStmts === []) {
continue;
}

$unreachableStatementNode = null;
foreach ($nextStmts as $nextStmt) {
if ($unreachableStatementNode instanceof UnreachableStatementNode) {
@@ -415,8 +425,9 @@ public function processStmtNodes(
}

$unreachableStatementNode = new UnreachableStatementNode($nextStmt);
$nodeCallback($unreachableStatementNode, $scope);
}

$nodeCallback($unreachableStatementNode, $scope);
}

$statementResult = new StatementResult($scope, $hasYield, $alreadyTerminated, $exitPoints, $throwPoints, $impurePoints);
@@ -6211,7 +6222,7 @@ private function getPhpDocReturnType(ResolvedPhpDocBlock $resolvedPhpDoc, Type $
/**
* @template T of Node
* @param array<T> $nodes
* @return Node\Stmt[]
* @return list<Node\Stmt>
*/
private function getNextUnreachableStatements(array $nodes, bool $earlyBinding): array
{
@@ -6223,7 +6234,7 @@ private function getNextUnreachableStatements(array $nodes, bool $earlyBinding):
if ($earlyBinding && ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassLike || $node instanceof Node\Stmt\HaltCompiler)) {
continue;
}
if (! $node instanceof Node\Stmt) {
if (!$node instanceof Node\Stmt) {
continue;
}
$stmts[] = $node;

0 comments on commit 211a0fb

Please sign in to comment.