diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index cb3c9b49d94..4f89f5de1d8 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -45,6 +45,8 @@ use Psalm\Internal\ReferenceConstraint; use Psalm\Internal\Scanner\ParsedDocblock; use Psalm\Internal\Type\Comparator\UnionTypeComparator; +use Psalm\Internal\Type\TypeParser; +use Psalm\Internal\Type\TypeTokenizer; use Psalm\Issue\CheckType; use Psalm\Issue\ComplexFunction; use Psalm\Issue\ComplexMethod; @@ -678,11 +680,23 @@ private static function analyzeStatement( } else { try { $checked_type = $context->vars_in_scope[$checked_var_id]; - $fq_check_type_string = Type::getFQCLNFromString( + + $path = $statements_analyzer->getRootFilePath(); + $file_storage = $codebase->file_storage_provider->get($path); + + $check_tokens = TypeTokenizer::getFullyQualifiedTokens( $check_type_string, $statements_analyzer->getAliases(), + $statements_analyzer->getTemplateTypeMap(), + $file_storage->type_aliases, + ); + $check_type = TypeParser::parseTokens( + $check_tokens, + null, + $statements_analyzer->getTemplateTypeMap() ?? [], + $file_storage->type_aliases, + true, ); - $check_type = Type::parseString($fq_check_type_string); /** @psalm-suppress InaccessibleProperty We just created this type */ $check_type->possibly_undefined = $possibly_undefined; diff --git a/tests/AssertAnnotationTest.php b/tests/AssertAnnotationTest.php index 5b619971f8e..83945999d87 100644 --- a/tests/AssertAnnotationTest.php +++ b/tests/AssertAnnotationTest.php @@ -2255,7 +2255,36 @@ function takesSomeIntFromEnum(int $foo): IntEnum function isNonEmptyString($_str): bool { return true; - }', + } + ', + ], + 'assertStringIsNonEmptyStringInNamespace' => [ + 'code' => ' [ 'code' => ' [ + 'code' => '