1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Allow named arguments to variadic functions (#4575)

Closes #4563
This commit is contained in:
Dusk 2020-11-16 12:49:27 -08:00 committed by GitHub
parent 09abcfb650
commit 0fe3e1f83b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -661,7 +661,7 @@ class ArgumentsAnalyzer
}
} 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;
}

View File

@ -259,6 +259,15 @@ class ArgTest extends TestCase
[],
'8.0'
],
'useNamedVariadicArguments' => [
'<?php
function takesArguments(int ...$args) : void {}
takesArguments(age: 5);',
[],
[],
'8.0'
],
];
}
@ -432,6 +441,16 @@ class ArgTest extends TestCase
false,
'8.0'
],
'wrongTypeVariadicArguments' => [
'<?php
function takesArguments(int ...$args) : void {}
takesArguments(age: "abc");',
'error_message' => 'InvalidScalarArgument',
[],
false,
'8.0'
],
];
}
}