1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix const reference in current context

This commit is contained in:
Matthew Brown 2019-03-03 16:43:24 -05:00
parent 472cdf6bea
commit fb9e9bea32
3 changed files with 10 additions and 2 deletions

View File

@ -34,6 +34,7 @@ class ConstFetchAnalyzer
Context $context
) {
$const_name = implode('\\', $stmt->name->parts);
switch (strtolower($const_name)) {
case 'null':
$stmt->inferredType = Type::getNull();

View File

@ -1354,8 +1354,8 @@ class StatementsAnalyzer extends SourceAnalyzer implements StatementsSource
}
}
if ($context->hasVariable($const_name, $statements_analyzer)) {
return $context->vars_in_scope[$const_name];
if ($context->hasVariable($fq_const_name, $this)) {
return $context->vars_in_scope[$fq_const_name];
}
$file_path = $statements_analyzer->getRootFilePath();

View File

@ -374,6 +374,13 @@ class ConstantTest extends TestCase
echo ns2\cons2;
}',
],
'allowConstantToBeDefinedInNamespaceNadReferenced' => [
'<?php
namespace ns;
function func(): void {}
define(__NAMESPACE__."\\cons", 0);
cons;'
],
];
}