mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Infer literal string for __namespace__
This commit is contained in:
parent
6b045236e0
commit
f603449745
@ -365,14 +365,6 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->source->getNamespace();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
|
@ -147,12 +147,27 @@ class ExpressionAnalyzer
|
||||
$stmt->inferredType = Type::getLiteralClassString($context->self);
|
||||
break;
|
||||
|
||||
case '__namespace__':
|
||||
$namespace = $statements_analyzer->getNamespace();
|
||||
if ($namespace === null &&
|
||||
IssueBuffer::accepts(
|
||||
new UndefinedConstant(
|
||||
'Cannot get __namespace__ outside a namespace',
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
|
||||
$stmt->inferredType = Type::getString($namespace);
|
||||
break;
|
||||
|
||||
case '__file__':
|
||||
case '__dir__':
|
||||
case '__function__':
|
||||
case '__trait__':
|
||||
case '__method__':
|
||||
case '__namespace__':
|
||||
$stmt->inferredType = Type::getString();
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user