Skip to content

Commit 5626c00

Browse files
committed
Fix define() before use statements breaking PHPDoc class resolution
- Removed !array_key_exists guard in FileTypeMapper::createPhpDocNodeMap() that prevented updating the name scope map entry after it was first set - The first non-skipped statement (e.g. define()) would lock in an empty $uses array for that scope key, causing later PHPDocs to fail resolving class names from use statements - New regression test in tests/PHPStan/Analyser/nsrt/bug-8950.php
1 parent 106fc93 commit 5626c00

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Type/FileTypeMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
541541
&& !$node instanceof Node\Stmt\InlineHTML
542542
&& !($node instanceof Node\Stmt\Expression && $node->expr instanceof Node\Expr\Include_)
543543
)
544-
) && !array_key_exists($nameScopeKey, $nameScopeMap)
544+
)
545545
) {
546546
$parentNameScope = array_last($typeMapStack) ?? null;
547547
$typeAliasesMap = array_last($typeAliasStack) ?? [];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Bug8950 {
4+
interface FooInterface
5+
{
6+
}
7+
}
8+
9+
namespace {
10+
11+
define('BUG_8950_FOO', 'foo');
12+
13+
use Bug8950\FooInterface;
14+
15+
/** @var FooInterface $foo */
16+
$foo = null;
17+
18+
\PHPStan\Testing\assertType('Bug8950\FooInterface', $foo);
19+
}

0 commit comments

Comments
 (0)