1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Allow class-string<T> where T is a union

This commit is contained in:
Rudolph Gottesheim 2023-09-11 13:34:40 +02:00
parent 7d8d74d32a
commit 3b775f4617
2 changed files with 21 additions and 6 deletions

View File

@ -462,12 +462,6 @@ class TypeParser
);
}
if (!$as->isSingle()) {
throw new TypeParseTreeException(
'Invalid templated classname \'' . $as . '\'',
);
}
foreach ($as->getAtomicTypes() as $t) {
if ($t instanceof TObject) {
return new TTemplateParamClass(

View File

@ -879,6 +879,27 @@ class ClassLikeStringTest extends TestCase
$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>',
],
],
];
}