Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closure param type inference with named params #7139

Merged
merged 1 commit into from Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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