Skip to content

Commit

Permalink
Merge pull request #10312 from trusting-thompson/named-param-out
Browse files Browse the repository at this point in the history
fix @param-out with named arguments
  • Loading branch information
orklah committed Oct 24, 2023
2 parents c7d7b48 + a375f44 commit ff5526d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Expand Up @@ -51,6 +51,7 @@
use UnexpectedValueException;

use function array_map;
use function array_reduce;
use function array_reverse;
use function array_slice;
use function array_values;
Expand Down Expand Up @@ -1031,7 +1032,26 @@ private static function handlePossiblyMatchingByRefParam(
$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;
Expand Down
18 changes: 18 additions & 0 deletions tests/ReferenceConstraintTest.php
Expand Up @@ -193,6 +193,24 @@ function takesNullableObj(?A &$a): bool { return true; }
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',
],
],
];
}

Expand Down

0 comments on commit ff5526d

Please sign in to comment.