Skip to content

Commit

Permalink
Allow class-string<T> where T is a union
Browse files Browse the repository at this point in the history
  • Loading branch information
MidnightDesign committed Sep 11, 2023
1 parent ea1664f commit a27a716
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/Psalm/Internal/Type/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions tests/ClassLikeStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,27 @@ class TypeTwo {}
$foo->baz = TypeTwo::class;
$foo->baz = TypeTwo::class;',
],
'classStringOfUnionTypeParameter' => [
'code' => '<?php
class A {}
class B {}
/**
* @template T as A|B
*
* @param class-string<T> $class
* @return class-string<T>
*/
function test(string $class): string {
return $class;
}
$r = test(A::class);',
'assertions' => [
'$r' => 'class-string<A>',
],
],
];
}

Expand Down

0 comments on commit a27a716

Please sign in to comment.