1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #2532 - fix templating inside class method when calling templated method

This commit is contained in:
Matthew Brown 2019-12-30 07:25:04 -05:00
parent 30d4ab5d62
commit 023c4bcef0
10 changed files with 43 additions and 3 deletions

View File

@ -1281,7 +1281,8 @@ class CallAnalyzer
$template_result,
$codebase,
$arg_value_type,
$context->self ?: 'fn-' . $context->calling_function_id,
$context->self,
$context->calling_function_id,
false
);
@ -1466,7 +1467,8 @@ class CallAnalyzer
$template_result,
$codebase,
clone $param->default_type,
'fn-' . $context->calling_function_id,
$context->self,
$context->calling_function_id,
true
);
}
@ -1804,7 +1806,8 @@ class CallAnalyzer
$template_result,
$codebase,
$arg_type_param,
$context->self ?: 'fn-' . $context->calling_function_id
$context->self,
$context->calling_function_id
);
foreach ($bindable_template_params as $template_type) {

View File

@ -23,6 +23,7 @@ class UnionTemplateHandler
?Codebase $codebase,
?Union $input_type,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0
@ -43,6 +44,7 @@ class UnionTemplateHandler
$codebase,
$input_type,
$calling_class,
$calling_function,
$replace,
$add_upper_bound,
$depth,
@ -87,6 +89,7 @@ class UnionTemplateHandler
?Codebase $codebase,
?Union $input_type,
?string $calling_class,
?string $calling_function,
bool $replace,
bool $add_upper_bound,
int $depth,
@ -106,6 +109,7 @@ class UnionTemplateHandler
$key,
$input_type,
$calling_class,
$calling_function,
$template_result,
$codebase,
$replace,
@ -243,6 +247,7 @@ class UnionTemplateHandler
$codebase,
$matching_atomic_type,
$calling_class,
$calling_function,
$replace,
$add_upper_bound,
$depth + 1
@ -365,6 +370,7 @@ class UnionTemplateHandler
string $key,
?Union $input_type,
?string $calling_class,
?string $calling_function,
TemplateResult $template_result,
?Codebase $codebase,
bool $replace,
@ -432,6 +438,7 @@ class UnionTemplateHandler
if ($replacement_atomic_type instanceof Atomic\TTemplateParam
&& $replacement_atomic_type->defining_class !== $calling_class
&& $replacement_atomic_type->defining_class !== 'fn-' . $calling_function
) {
foreach ($replacement_atomic_type->as->getTypes() as $nested_type_atomic) {
$replacements_found = true;

View File

@ -816,6 +816,7 @@ abstract class Atomic
Codebase $codebase = null,
Type\Atomic $input_type = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0

View File

@ -199,6 +199,7 @@ trait CallableTrait
Codebase $codebase = null,
Atomic $input_type = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0
@ -225,6 +226,7 @@ trait CallableTrait
$codebase,
$input_param_type,
$calling_class,
$calling_function,
$replace,
!$add_upper_bound,
$depth
@ -242,6 +244,7 @@ trait CallableTrait
$codebase,
$input_type->return_type,
$calling_class,
$calling_function,
$replace,
$add_upper_bound
);

View File

@ -158,6 +158,7 @@ trait GenericTrait
Codebase $codebase = null,
Atomic $input_type = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0
@ -195,6 +196,7 @@ trait GenericTrait
$codebase,
$input_type_param,
$calling_class,
$calling_function,
$replace,
$add_upper_bound,
$depth + 1

View File

@ -324,6 +324,7 @@ class ObjectLike extends \Psalm\Type\Atomic
Codebase $codebase = null,
Atomic $input_type = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0
@ -345,6 +346,7 @@ class ObjectLike extends \Psalm\Type\Atomic
$codebase,
$input_type_param,
$calling_class,
$calling_function,
$replace,
$add_upper_bound,
$depth

View File

@ -149,6 +149,7 @@ class TClassStringMap extends \Psalm\Type\Atomic
Codebase $codebase = null,
Atomic $input_type = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0
@ -185,6 +186,7 @@ class TClassStringMap extends \Psalm\Type\Atomic
$codebase,
$input_type_param,
$calling_class,
$calling_function,
$replace,
$add_upper_bound,
$depth + 1

View File

@ -119,6 +119,7 @@ class TList extends \Psalm\Type\Atomic
Codebase $codebase = null,
Atomic $input_type = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0
@ -155,6 +156,7 @@ class TList extends \Psalm\Type\Atomic
$codebase,
$input_type_param,
$calling_class,
$calling_function,
$replace,
$add_upper_bound,
$depth + 1

View File

@ -247,6 +247,7 @@ class TObjectWithProperties extends TObject
Codebase $codebase = null,
Atomic $input_type = null,
?string $calling_class = null,
?string $calling_function = null,
bool $replace = true,
bool $add_upper_bound = false,
int $depth = 0
@ -268,6 +269,7 @@ class TObjectWithProperties extends TObject
$codebase,
$input_type_param,
$calling_class,
$calling_function,
$replace,
$add_upper_bound,
$depth

View File

@ -2203,6 +2203,22 @@ class ClassTemplateTest extends TestCase
}
}'
],
'uasortCallableInMethod' => [
'<?php
class C {
/**
* @template T of object
* @psalm-param array<T> $collection
* @psalm-param callable(T, T): int $sorter
* @psalm-return array<T>
*/
function order(array $collection, callable $sorter): array {
usort($collection, $sorter);
return $collection;
}
}'
],
];
}