1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Support template-typeof in class again

This commit is contained in:
Matthew Brown 2019-01-13 14:29:04 -05:00
parent 1de0e35545
commit 2c55e7aabb
2 changed files with 34 additions and 1 deletions

View File

@ -1720,6 +1720,10 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
? $template_types[$template_typeof['template_type']][0]
: null;
$template_class = isset($template_types[$template_typeof['template_type']])
? $template_types[$template_typeof['template_type']][1]
: null;
$param->type = new Type\Union([
new Type\Atomic\TGenericParamClass(
$template_typeof['template_type'],
@ -1728,7 +1732,8 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
: 'object',
$template_type && $template_type->isMixed()
? null
: $template_type
: $template_type,
$template_class
)
]);

View File

@ -1113,6 +1113,34 @@ class TemplateTest extends TestCase
'assertions' => [],
'error_levels' => ['MixedMethodCall'],
],
'returnTemplatedClassClassName' => [
'<?php
class I {
/**
* @template T as Foo
* @param class-string $class
* @template-typeof T $class
* @return T|null
*/
public function loader(string $class) : void {
return $class::load();
}
}
class Foo {
/** @return static */
public static function load() {
return new static();
}
}
class FooChild extends Foo{}
$a = (new I)->loader(FooChild::class);',
'assertions' => [
'$a' => 'null|FooChild',
],
],
'upcastIterableToTraversable' => [
'<?php
/**