mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Understand that template class string transforms back to templated class
Fixes #1250
This commit is contained in:
parent
cd4d2027d0
commit
00e95cbd6b
@ -868,6 +868,13 @@ class Union
|
||||
$valid_input_atomic_types[] = new Type\Atomic\TNamedObject(
|
||||
$input_atomic_type->value
|
||||
);
|
||||
} elseif ($input_atomic_type instanceof Type\Atomic\TGenericParamClass) {
|
||||
$valid_input_atomic_types[] = new Type\Atomic\TGenericParam(
|
||||
$input_atomic_type->param_name,
|
||||
$input_atomic_type->as_type
|
||||
? new Union([$input_atomic_type->as_type])
|
||||
: Type::getMixed()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1459,6 +1459,26 @@ class TemplateTest extends TestCase
|
||||
'$partB' => 'Collection<int, string>',
|
||||
]
|
||||
],
|
||||
'understandTemplatedCalculationInOtherFunction' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T as Exception
|
||||
* @param T::class $type
|
||||
* @return T
|
||||
*/
|
||||
function a(string $type): Exception {
|
||||
return new $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T as InvalidArgumentException
|
||||
* @param T::class $type
|
||||
* @return T
|
||||
*/
|
||||
function b(string $type): InvalidArgumentException {
|
||||
return a($type);
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user