diff --git a/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php b/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php index 5bd43d4f5a8..268ae67e7ec 100644 --- a/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php +++ b/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php @@ -38,7 +38,9 @@ public function enterNode(Node $node): ?Node $mutatingScope = $this->resolveScope($node->getAttribute(AttributeKey::SCOPE)); foreach ($node->stmts as $stmt) { - if (! $stmt->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) { + $hasMutatingScope = $stmt->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope; + if (! $hasMutatingScope) { + $stmt->setAttribute(AttributeKey::SCOPE, $mutatingScope); $this->phpStanNodeScopeResolver->processNodes([$stmt], $this->filePath, $mutatingScope); } @@ -49,7 +51,6 @@ public function enterNode(Node $node): ?Node if ($isPassedUnreachableStmt) { $stmt->setAttribute(AttributeKey::IS_UNREACHABLE, true); - $stmt->setAttribute(AttributeKey::SCOPE, $mutatingScope); } }