From fb9e9bea328940516746154f7bc6da7b30a574c1 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 3 Mar 2019 16:43:24 -0500 Subject: [PATCH] Fix const reference in current context --- .../Statements/Expression/Fetch/ConstFetchAnalyzer.php | 1 + src/Psalm/Internal/Analyzer/StatementsAnalyzer.php | 4 ++-- tests/ConstantTest.php | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php index 3e97fbb3c..4584e9d09 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php @@ -34,6 +34,7 @@ class ConstFetchAnalyzer Context $context ) { $const_name = implode('\\', $stmt->name->parts); + switch (strtolower($const_name)) { case 'null': $stmt->inferredType = Type::getNull(); diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index eed356753..318eeddf7 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -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(); diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index f51ad1721..5ed7a37ae 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -374,6 +374,13 @@ class ConstantTest extends TestCase echo ns2\cons2; }', ], + 'allowConstantToBeDefinedInNamespaceNadReferenced' => [ + '