Skip to content

Commit

Permalink
Fix #2439 - fix templating of class-string<T>::returnsStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 9, 2019
1 parent 69e6624 commit e3d108e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -891,7 +891,8 @@ function (PhpParser\Node\Arg $arg) {
$lhs_type_part->param_name, $lhs_type_part->param_name,
$lhs_type_part->as_type $lhs_type_part->as_type
? new Type\Union([$lhs_type_part->as_type]) ? new Type\Union([$lhs_type_part->as_type])
: Type::getObject() : Type::getObject(),
$lhs_type_part->defining_class
); );
} else { } else {
$static_type = $fq_class_name; $static_type = $fq_class_name;
Expand Down
35 changes: 35 additions & 0 deletions tests/Template/ClassTemplateTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2131,6 +2131,41 @@ function __construct(array $arr) {
*/ */
function copyMapUsingProperty(Map $map): Map { function copyMapUsingProperty(Map $map): Map {
return new Map($map->arr); return new Map($map->arr);
}',
],
'mapStaticClassTemplatedFromClassString' => [
'<?php
class Base {
/** @return static */
public static function factory(): self {
return new self();
}
}
/**
* @template T of Base
* @param class-string<T> $t
* @return T
*/
function f(string $t) {
return $t::factory();
}
/** @template T of Base */
class C {
/** @var class-string<T> */
private string $t;
/** @param class-string<T> $t */
public function __construct($t) {
$this->t = $t;
}
/** @return T */
public function f(): Base {
$t = $this->t;
return $t::factory();
}
}' }'
], ],
]; ];
Expand Down

0 comments on commit e3d108e

Please sign in to comment.