From 3b775f46171ce6ef8b1b4f124b71b5aaa84cd66a Mon Sep 17 00:00:00 2001 From: Rudolph Gottesheim Date: Mon, 11 Sep 2023 13:34:40 +0200 Subject: [PATCH] Allow class-string where T is a union --- src/Psalm/Internal/Type/TypeParser.php | 6 ------ tests/ClassLikeStringTest.php | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index 4707ff9a8d4..99cf82a4d51 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -462,12 +462,6 @@ private static function getGenericParamClass( ); } - if (!$as->isSingle()) { - throw new TypeParseTreeException( - 'Invalid templated classname \'' . $as . '\'', - ); - } - foreach ($as->getAtomicTypes() as $t) { if ($t instanceof TObject) { return new TTemplateParamClass( diff --git a/tests/ClassLikeStringTest.php b/tests/ClassLikeStringTest.php index 1e7f5b9eaab..b3bcca56121 100644 --- a/tests/ClassLikeStringTest.php +++ b/tests/ClassLikeStringTest.php @@ -879,6 +879,27 @@ class TypeTwo {} $foo->baz = TypeTwo::class; $foo->baz = TypeTwo::class;', ], + 'classStringOfUnionTypeParameter' => [ + 'code' => ' $class + * @return class-string + */ + function test(string $class): string { + return $class; + } + + $r = test(A::class);', + 'assertions' => [ + '$r' => 'class-string', + ], + ], ]; }