From fa8541a014d921a0993f6605a66bcd6b9bfd9fcd Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 30 Dec 2024 13:16:28 +0100 Subject: [PATCH] PreviousConnectingVisitor: Utilize WeakReference --- src/Ast/ExpressionFinder.php | 4 ++++ src/Ast/PreviousConnectingVisitor.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Ast/ExpressionFinder.php b/src/Ast/ExpressionFinder.php index 492b569ed..7fe0e2ee3 100644 --- a/src/Ast/ExpressionFinder.php +++ b/src/Ast/ExpressionFinder.php @@ -134,6 +134,10 @@ private function findFirstPreviousOfNode(Node $node, callable $filter): ?Node // move to previous expression $previousStatement = $node->getAttribute(PreviousConnectingVisitor::ATTRIBUTE_PREVIOUS); if (null !== $previousStatement) { + if ($previousStatement instanceof \WeakReference) { + $previousStatement = $previousStatement->get(); + } + if (! $previousStatement instanceof Node) { throw new ShouldNotHappenException(); } diff --git a/src/Ast/PreviousConnectingVisitor.php b/src/Ast/PreviousConnectingVisitor.php index db9111761..d303680ca 100644 --- a/src/Ast/PreviousConnectingVisitor.php +++ b/src/Ast/PreviousConnectingVisitor.php @@ -39,7 +39,7 @@ public function enterNode(Node $node) && ! $this->previous instanceof Node\Stmt\ClassLike && ! $this->previous instanceof VirtualNode ) { - $node->setAttribute(self::ATTRIBUTE_PREVIOUS, $this->previous); + $node->setAttribute(self::ATTRIBUTE_PREVIOUS, \WeakReference::create($this->previous)); } return null;