From 27e0f91efad4c9fcacae98b2e3394c069e9e5095 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sat, 20 Jul 2024 10:14:16 +0200 Subject: [PATCH] ExecutionEndNode always has a statement --- src/Analyser/NodeScopeResolver.php | 6 +++++- src/Node/ExecutionEndNode.php | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 226bedd4f5..c1184e26d1 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -394,10 +394,14 @@ public function processStmtNodes( if ($stmtCount === 0 && $shouldCheckLastStatement) { /** @var Node\Stmt\Function_|Node\Stmt\ClassMethod|Expr\Closure $parentNode */ $parentNode = $parentNode; + $returnTypeNode = $parentNode->returnType; + if ($parentNode instanceof Expr\Closure) { + $parentNode = new Node\Stmt\Expression($parentNode, $parentNode->getAttributes()); + } $nodeCallback(new ExecutionEndNode( $parentNode, $statementResult, - $parentNode->returnType !== null, + $returnTypeNode !== null, ), $scope); } diff --git a/src/Node/ExecutionEndNode.php b/src/Node/ExecutionEndNode.php index 225036a5ba..c0a0f52dd8 100644 --- a/src/Node/ExecutionEndNode.php +++ b/src/Node/ExecutionEndNode.php @@ -11,7 +11,7 @@ class ExecutionEndNode extends NodeAbstract implements VirtualNode { public function __construct( - private Node $node, + private Node\Stmt $node, private StatementResult $statementResult, private bool $hasNativeReturnTypehint, ) @@ -19,7 +19,7 @@ public function __construct( parent::__construct($node->getAttributes()); } - public function getNode(): Node + public function getNode(): Node\Stmt { return $this->node; }