1
0
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:
orklah 2021-12-12 11:24:54 +01:00 committed by GitHub
commit 2a570fb94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -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) {

View File

@ -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 {