Skip to content

Commit

Permalink
Allow named arguments to variadic functions (vimeo#4575)
Browse files Browse the repository at this point in the history
Closes vimeo#4563
  • Loading branch information
duskwuff authored and danog committed Jan 29, 2021
1 parent ff55dba commit 4e7bd1e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ public static function checkArgumentsMatch(
}
} elseif ($arg->name && $function_storage && $function_storage->allow_named_arg_calls) {
foreach ($function_params as $candidate_param) {
if ($candidate_param->name === $arg->name->name) {
if ($candidate_param->name === $arg->name->name || $candidate_param->is_variadic) {
$arg_function_params = [$candidate_param];
break;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/ArgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ function takesArguments(string $name, int $age) : void {}
[],
'8.0'
],
'useNamedVariadicArguments' => [
'<?php
function takesArguments(int ...$args) : void {}
takesArguments(age: 5);',
[],
[],
'8.0'
],
];
}

Expand Down Expand Up @@ -432,6 +441,16 @@ function processUserDataInvalid(array $data) : User {
false,
'8.0'
],
'wrongTypeVariadicArguments' => [
'<?php
function takesArguments(int ...$args) : void {}
takesArguments(age: "abc");',
'error_message' => 'InvalidScalarArgument',
[],
false,
'8.0'
],
];
}
}

0 comments on commit 4e7bd1e

Please sign in to comment.