mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #830 - unpack template param args appropriately
This commit is contained in:
parent
4688cf7a92
commit
740279352e
@ -829,11 +829,28 @@ class CallChecker
|
||||
$generic_params = [];
|
||||
}
|
||||
|
||||
$arg_type = $arg->value->inferredType;
|
||||
|
||||
if ($arg->unpack) {
|
||||
if ($arg->value->inferredType->hasArray()) {
|
||||
/** @var Type\Atomic\TArray|Type\Atomic\ObjectLike */
|
||||
$array_atomic_type = $arg->value->inferredType->getTypes()['array'];
|
||||
|
||||
if ($array_atomic_type instanceof Type\Atomic\ObjectLike) {
|
||||
$array_atomic_type = $array_atomic_type->getGenericArrayType();
|
||||
}
|
||||
|
||||
$arg_type = $array_atomic_type->type_params[1];
|
||||
} else {
|
||||
$arg_type = Type::getMixed();
|
||||
}
|
||||
}
|
||||
|
||||
$param_type->replaceTemplateTypesWithStandins(
|
||||
$template_types,
|
||||
$generic_params,
|
||||
$codebase,
|
||||
$arg->value->inferredType
|
||||
$arg_type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -701,6 +701,18 @@ class FunctionCallTest extends TestCase
|
||||
["foo" => "bar"]
|
||||
);'
|
||||
],
|
||||
'splatArrayIntersect' => [
|
||||
'<?php
|
||||
$foo = [
|
||||
[1, 2, 3],
|
||||
[1, 2],
|
||||
];
|
||||
|
||||
$bar = array_intersect(... $foo);',
|
||||
'assertions' => [
|
||||
'$bar' => 'array<int, int>',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -684,6 +684,30 @@ class TemplateTest extends TestCase
|
||||
function(Collection $elt): bool { return true; }
|
||||
);',
|
||||
],
|
||||
'splatTemplateParam' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template TKey
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, TValue> $arr
|
||||
* @param array $arr2
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
function splat_proof(array $arr, array $arr2) {
|
||||
return $arr;
|
||||
}
|
||||
|
||||
$foo = [
|
||||
[1, 2, 3],
|
||||
[1, 2],
|
||||
];
|
||||
|
||||
$a = splat_proof(... $foo);',
|
||||
'assertions' => [
|
||||
'$a' => 'array<int, int>',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user