diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 061860600d..011c49f341 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -355,11 +355,6 @@ private function processStmtNode( ): StatementResult { if ( - $stmt instanceof Throw_ - || $stmt instanceof Return_ - ) { - $scope = $this->processStmtVarAnnotation($scope, $stmt, $stmt->expr, $nodeCallback); - } elseif ( !$stmt instanceof Static_ && !$stmt instanceof Foreach_ && !$stmt instanceof Node\Stmt\Global_ @@ -392,7 +387,12 @@ private function processStmtNode( } } - $nodeCallback($stmt, $scope); + $stmtScope = $scope; + if ($stmt instanceof Throw_ || $stmt instanceof Return_) { + $stmtScope = $this->processStmtVarAnnotation($scope, $stmt, $stmt->expr, $nodeCallback); + } + + $nodeCallback($stmt, $stmtScope); $overridingThrowPoints = $this->getOverridingThrowPoints($stmt, $scope); diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index e1bbfc2f70..60bfe73d8b 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1176,6 +1176,14 @@ public function testBug5091(): void $this->assertNoErrors($errors); } + public function testBug9459(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-9459.php'); + $this->assertCount(1, $errors); + $this->assertSame('PHPDoc tag @var with type callable(): array is not subtype of native type Closure(): array{}.', $errors[0]->getMessage()); + $this->assertSame(10, $errors[0]->getLine()); + } + public function testDiscussion9053(): void { if (PHP_VERSION_ID < 80000) { diff --git a/tests/PHPStan/Analyser/data/bug-9459.php b/tests/PHPStan/Analyser/data/bug-9459.php new file mode 100644 index 0000000000..684dc72470 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-9459.php @@ -0,0 +1,12 @@ +