From 57af279308404f6a71713b8823d9ed35186cba84 Mon Sep 17 00:00:00 2001 From: tuqqu Date: Fri, 13 Oct 2023 00:03:53 +0200 Subject: [PATCH] Fix for inferring enum case value from a class constant, const test fix --- .../Analyzer/Statements/Expression/SimpleTypeInferer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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,