diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php index cfd69cb3784..841e6f516aa 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php @@ -12,6 +12,7 @@ use Psalm\Internal\Analyzer\Statements\Expression\BinaryOp\ArithmeticOpAnalyzer; use Psalm\Internal\Analyzer\StatementsAnalyzer; use Psalm\Internal\Provider\NodeDataProvider; +use Psalm\Internal\Scanner\FileScanner; use Psalm\Internal\Type\TypeCombiner; use Psalm\StatementsSource; use Psalm\Storage\ClassConstantStorage; @@ -337,7 +338,10 @@ public static function infer( return Type::getLiteralClassString($const_fq_class_name, true); } - if ($existing_class_constants === null || $existing_class_constants === []) { + if ($file_source instanceof FileScanner + && $existing_class_constants === null + || $existing_class_constants === [] + ) { try { $foreign_class_constant = $codebase->classlikes->getClassConstantType( $const_fq_class_name,