Skip to content

Commit

Permalink
Merge pull request #10194 from MidnightDesign/issue-8582
Browse files Browse the repository at this point in the history
Allow class-string<T> where T is a union
  • Loading branch information
orklah authored Sep 28, 2023
2 parents a70b2c0 + 3b775f4 commit d7236ef
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 d7236ef

Please sign in to comment.