Skip to content

Commit 70b1ee0

Browse files
Fix spurious error in specific combination of namespace blocks and function declaration with phpdoc type annotation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 0585d62 commit 70b1ee0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,8 @@ private function processStmtNode(
10101010
} elseif ($stmt instanceof Node\Stmt\Namespace_) {
10111011
if ($stmt->name !== null) {
10121012
$scope = $scope->enterNamespace($stmt->name->toString());
1013+
} else {
1014+
$scope = $scope->enterNamespace('');
10131015
}
10141016

10151017
$scope = $this->processStmtNodesInternal($stmt, $stmt->stmts, $scope, $storage, $nodeCallback, $context)->getScope();

tests/PHPStan/Rules/Functions/MissingFunctionReturnTypehintRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ public function testRule(): void
8282
]);
8383
}
8484

85+
public function testBug13831(): void
86+
{
87+
$this->analyse([__DIR__ . '/data/bug-13831.php'], []);
88+
}
89+
8590
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bug13831 {
4+
// non-global namespace block
5+
}
6+
7+
namespace {
8+
9+
/** @return list<string> */
10+
function bug13831Qux(): array {
11+
return [ random_bytes(16) ];
12+
}
13+
14+
}

0 commit comments

Comments
 (0)