mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #7139 from klimick/fix-closure-type-inference-named-params
Fix closure param type inference with named params
This commit is contained in:
commit
2a570fb94f
@ -127,6 +127,10 @@ class ArgumentsAnalyzer
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($last_param && $last_param->is_variadic) {
|
||||
$param = $last_param;
|
||||
}
|
||||
} elseif ($argument_offset < count($function_params)) {
|
||||
$param = $function_params[$argument_offset];
|
||||
} elseif ($last_param && $last_param->is_variadic) {
|
||||
|
@ -85,6 +85,31 @@ class CallableTest extends TestCase
|
||||
'error_levels' => [],
|
||||
'7.4',
|
||||
],
|
||||
'inferArgFromClassContextWithNamedArguments' => [
|
||||
'<?php
|
||||
final class Calc
|
||||
{
|
||||
/**
|
||||
* @param Closure(int, int): int ...$_fn
|
||||
*/
|
||||
public function __invoke(Closure ...$_fn): int
|
||||
{
|
||||
throw new RuntimeException("???");
|
||||
}
|
||||
}
|
||||
|
||||
$calc = new Calc();
|
||||
|
||||
$a = $calc(
|
||||
foo: fn($_a, $_b) => $_a + $_b,
|
||||
bar: fn($_a, $_b) => $_a + $_b,
|
||||
);',
|
||||
'assertions' => [
|
||||
'$a' => 'int',
|
||||
],
|
||||
'error_levels' => [],
|
||||
'7.4',
|
||||
],
|
||||
'varReturnType' => [
|
||||
'<?php
|
||||
$add_one = function(int $a) : int {
|
||||
|
Loading…
Reference in New Issue
Block a user