From 6d32d2f69276b31723c98f590f68866972839187 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Tue, 30 Jan 2024 20:29:51 +0100 Subject: [PATCH] Allow importing typedefs from enums Fixes vimeo/psalm#10416 --- src/Psalm/Internal/Type/TypeExpander.php | 2 +- tests/TypeAnnotationTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index 795b5ad9a8a..61af641066f 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -283,7 +283,7 @@ public static function expandAtomic( $declaring_fq_classlike_name = $self_class; } - if (!($evaluate_class_constants && $codebase->classOrInterfaceExists($declaring_fq_classlike_name))) { + if (!($evaluate_class_constants && $codebase->classOrInterfaceOrEnumExists($declaring_fq_classlike_name))) { return [$return_type]; } diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 29ee8f6581f..dbcbf0b987d 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -865,6 +865,25 @@ public function doesNotWork($_doesNotWork): void { } }', ], + 'importFromEnum' => [ + 'code' => <<<'PHP' + [], + 'ignored_issues' => [], + 'php_version' => '8.1', + ], ]; }