Skip to content

Commit 525a9fa

Browse files
authored
PreviousConnectingVisitor: Utilize WeakReference (#730)
1 parent 675388c commit 525a9fa

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Ast/ExpressionFinder.php

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ private function findFirstPreviousOfNode(Node $node, callable $filter): ?Node
134134
// move to previous expression
135135
$previousStatement = $node->getAttribute(PreviousConnectingVisitor::ATTRIBUTE_PREVIOUS);
136136
if (null !== $previousStatement) {
137+
if ($previousStatement instanceof \WeakReference) {
138+
$previousStatement = $previousStatement->get();
139+
}
140+
137141
if (! $previousStatement instanceof Node) {
138142
throw new ShouldNotHappenException();
139143
}

src/Ast/PreviousConnectingVisitor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function enterNode(Node $node)
3939
&& ! $this->previous instanceof Node\Stmt\ClassLike
4040
&& ! $this->previous instanceof VirtualNode
4141
) {
42-
$node->setAttribute(self::ATTRIBUTE_PREVIOUS, $this->previous);
42+
$node->setAttribute(self::ATTRIBUTE_PREVIOUS, \WeakReference::create($this->previous));
4343
}
4444

4545
return null;

0 commit comments

Comments
 (0)