1
0
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:
Matthew Brown 2019-01-27 15:08:17 -05:00
parent cd4d2027d0
commit 00e95cbd6b
2 changed files with 27 additions and 0 deletions

View File

@ -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()
);
}
}

View File

@ -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);
}',
],
];
}