Skip to content

Commit

Permalink
Fix resolving docblocks in global namespace (using namespace {})
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen authored and ondrejmirtes committed Sep 26, 2022
1 parent 35c11fa commit 60cf8a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Type/FileTypeMapper.php
Expand Up @@ -367,7 +367,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
}

if ($node instanceof Node\Stmt\Namespace_) {
$namespace = (string) $node->name;
$namespace = $node->name !== null ? (string) $node->name : null;
} elseif ($node instanceof Node\Stmt\Use_) {
if ($node->type === Node\Stmt\Use_::TYPE_NORMAL) {
foreach ($node->uses as $use) {
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -1042,6 +1042,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7963-three.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8017.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8004.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/global-namespace.php');
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/data/global-namespace.php
@@ -0,0 +1,18 @@
<?php

namespace {

use function PHPStan\Testing\assertType;

/**
* @return Exception
*/
function globalNamespaceTest()
{
return new Exception();
}

function () {
assertType('Exception', globalNamespaceTest());
};
}

0 comments on commit 60cf8a9

Please sign in to comment.