1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix issue resolving namespaced constants

This commit is contained in:
Matt Brown 2018-08-08 16:13:37 -04:00
parent 2636b194db
commit 226aa27686
3 changed files with 10 additions and 4 deletions

View File

@ -404,12 +404,14 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
$const_type = StatementsChecker::getSimpleType($this->codebase, $const->value, $this->aliases)
?: Type::getMixed();
$fq_const_name = Type::getFQCLNFromString($const->name->name, $this->aliases);
if ($this->codebase->register_stub_files || $this->codebase->register_autoload_files) {
$this->codebase->addGlobalConstantType($const->name->name, $const_type);
$this->codebase->addGlobalConstantType($fq_const_name, $const_type);
}
$this->file_storage->constants[$const->name->name] = $const_type;
$this->file_storage->declaring_constants[$const->name->name] = $this->file_path;
$this->file_storage->constants[$fq_const_name] = $const_type;
$this->file_storage->declaring_constants[$fq_const_name] = $this->file_path;
}
} elseif ($this->codebase->register_autoload_files && $node instanceof PhpParser\Node\Stmt\If_) {
if ($node->cond instanceof PhpParser\Node\Expr\BooleanNot) {

View File

@ -146,7 +146,9 @@ class StubTest extends TestCase
echo Foo\SystemClass::HELLO;
$b = $a->foo(5, "hello");
$c = Foo\SystemClass::bar(5, "hello");'
$c = Foo\SystemClass::bar(5, "hello");
echo Foo\BAR;'
);
$this->analyzeFile($file_path, new Context());

View File

@ -2,6 +2,8 @@
namespace Foo;
const BAR = "bat";
class SystemClass {
const HELLO = 'hello';