Skip to content

Commit

Permalink
handle variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Oct 22, 2022
1 parent 2c47d06 commit edeff14
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php
Expand Up @@ -144,11 +144,16 @@ public static function isContainedBy(
&& is_array($container_type_part->params)
&& $input_type_part instanceof TCallable
) {
$container_all_param_count = count($container_type_part->params);
$container_required_param_count = 0;
foreach ($container_type_part->params as $index => $container_param) {
if ($container_param->is_optional === false) {
$container_required_param_count = $index + 1;
}

if ($container_param->is_variadic === true) {
$container_all_param_count = PHP_INT_MAX;
}
}

$input_required_param_count = 0;
Expand All @@ -161,12 +166,16 @@ public static function isContainedBy(
if ($input_param->is_optional === false) {
$input_required_param_count = $index + 1;
}

if ($input_param->is_variadic === true) {
$input_all_param_count = PHP_INT_MAX;
}
}
}

// too few or too many non-optional params provided in callback
if ($container_required_param_count > $input_all_param_count
|| count($container_type_part->params) < $input_required_param_count
|| $container_all_param_count < $input_required_param_count
) {
return false;
}
Expand Down

0 comments on commit edeff14

Please sign in to comment.