mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
fix @param-out with named arguments
This commit is contained in:
parent
c7d7b48bdd
commit
a375f441f2
@ -51,6 +51,7 @@ use Psalm\Type\Union;
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function array_map;
|
||||
use function array_reduce;
|
||||
use function array_reverse;
|
||||
use function array_slice;
|
||||
use function array_values;
|
||||
@ -1031,7 +1032,26 @@ class ArgumentsAnalyzer
|
||||
$check_null_ref = true;
|
||||
|
||||
if ($last_param) {
|
||||
if ($argument_offset < count($function_params)) {
|
||||
if ($arg->name !== null) {
|
||||
$function_param = array_reduce(
|
||||
$function_params,
|
||||
static function (
|
||||
?FunctionLikeParameter $function_param,
|
||||
FunctionLikeParameter $param
|
||||
) use (
|
||||
$arg
|
||||
) {
|
||||
if ($param->name === $arg->name->name) {
|
||||
return $param;
|
||||
}
|
||||
return $function_param;
|
||||
},
|
||||
null,
|
||||
);
|
||||
if ($function_param === null) {
|
||||
return false;
|
||||
}
|
||||
} elseif ($argument_offset < count($function_params)) {
|
||||
$function_param = $function_params[$argument_offset];
|
||||
} else {
|
||||
$function_param = $last_param;
|
||||
|
@ -193,6 +193,24 @@ class ReferenceConstraintTest extends TestCase
|
||||
|
||||
if ($a) {}',
|
||||
],
|
||||
'PHP80-paramOutChangeTypeWithNamedArgument' => [
|
||||
'code' => '<?php
|
||||
/**
|
||||
* @param-out int $s
|
||||
*/
|
||||
function addFoo(bool $five = true, ?string &$s = null) : void {
|
||||
if ($five) {
|
||||
$s = 5;
|
||||
return;
|
||||
}
|
||||
$s = 4;
|
||||
}
|
||||
|
||||
addFoo(s: $a);',
|
||||
'assertions' => [
|
||||
'$a' => 'int',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user