From 6140f6881c3a83eca20be295454562ced3645255 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Wed, 31 Jan 2024 23:07:23 +0100 Subject: [PATCH] Allow typedef imports from any classlike type All we really need is for the source to be autoloadable, and it includes all classlikes (interfaces, classes, enums and traits at the time of writing). --- src/Psalm/Internal/Analyzer/FileAnalyzer.php | 2 +- src/Psalm/Internal/Type/TypeExpander.php | 4 +++- tests/TypeAnnotationTest.php | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/FileAnalyzer.php b/src/Psalm/Internal/Analyzer/FileAnalyzer.php index d98795589..80db22ed9 100644 --- a/src/Psalm/Internal/Analyzer/FileAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FileAnalyzer.php @@ -237,7 +237,7 @@ class FileAnalyzer extends SourceAnalyzer $this->suppressed_issues, new ClassLikeNameOptions( true, - false, + true, true, true, true, diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index 61af64106..0855a1ab7 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -283,7 +283,9 @@ final class TypeExpander $declaring_fq_classlike_name = $self_class; } - if (!($evaluate_class_constants && $codebase->classOrInterfaceOrEnumExists($declaring_fq_classlike_name))) { + if (!($evaluate_class_constants + && $codebase->classlikes->doesClassLikeExist(strtolower($declaring_fq_classlike_name)) + )) { return [$return_type]; } diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index ea4d4be65..0e101137c 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -884,6 +884,21 @@ class TypeAnnotationTest extends TestCase 'ignored_issues' => [], 'php_version' => '8.1', ], + 'importFromTrait' => [ + 'code' => <<<'PHP' + [ 'code' => <<<'PHP'