Skip to content

Commit

Permalink
Merge pull request #7139 from klimick/fix-closure-type-inference-name…
Browse files Browse the repository at this point in the history
…d-params

Fix closure param type inference with named params
  • Loading branch information
orklah committed Dec 12, 2021
2 parents 41ca7f7 + a8d2353 commit 2a570fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Expand Up @@ -127,6 +127,10 @@ public static function analyze(
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) {
Expand Down
25 changes: 25 additions & 0 deletions tests/CallableTest.php
Expand Up @@ -85,6 +85,31 @@ public function __invoke(Closure $_fn): int
'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 {
Expand Down

0 comments on commit 2a570fb

Please sign in to comment.