Skip to content
Permalink
Browse files

Fix leaky template type

  • Loading branch information...
muglug committed May 24, 2019
1 parent 3e2b716 commit 7a48225184d26438a0475c08c928ecb47d0202c6
@@ -752,7 +752,7 @@ function (PhpParser\Node\Arg $arg) {
if ($return_type_candidate) {
$return_type_candidate = clone $return_type_candidate;
if ($found_generic_params) {
if ($found_generic_params !== null) {
$return_type_candidate->replaceTemplateTypesWithArgTypes(
$found_generic_params
);
@@ -1314,7 +1314,11 @@ public function replaceTemplateTypesWithArgTypes(array $template_types, Codebase
$new_types[$template_type_part->getKey()] = $template_type_part;
}
} else {
$new_types[$key] = $atomic_type;
if ($atomic_type->as->isSingle()) {
$new_types[$key] = array_values($atomic_type->as->getTypes())[0];
} else {
$new_types[$key] = new Type\Atomic\TMixed;
}
}
} elseif ($atomic_type instanceof Type\Atomic\TTemplateParamClass) {
$template_type = isset($template_types[$atomic_type->param_name][$atomic_type->defining_class ?: ''])
@@ -1626,7 +1626,7 @@ function() {
'$arr' => 'array<int, string>',
],
],
'templatedClassStringParam' => [
'templatedClassStringParamAsClass' => [
'<?php
abstract class C {
public function foo() : void{}
@@ -1663,6 +1663,32 @@ function bat(string $c_class) : void {
$c->foo();
}',
],
'templatedClassStringParamAsObject' => [
'<?php
abstract class C {
public function foo() : void{}
}
class E {
/**
* @template T as object
* @param class-string<T> $c_class
*
* @psalm-return T
*/
public static function get(string $c_class) {
return new $c_class;
}
}
/**
* @psalm-suppress TypeCoercion
*/
function bat(string $c_class) : void {
$c = E::get($c_class);
$c->bar = "bax";
}',
],
'templatedClassStringParamMoreSpecific' => [
'<?php
abstract class C {

0 comments on commit 7a48225

Please sign in to comment.
You can’t perform that action at this time.