Skip to content

Commit

Permalink
Return earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 5, 2020
1 parent eb9d6f6 commit 1bb8b73
Showing 1 changed file with 55 additions and 55 deletions.
Expand Up @@ -1214,73 +1214,73 @@ private static function getProvisionalTemplateResultForFunctionLike(
$class_generic_params
);

if ($template_types) {
if ($class_template_result) {
$template_result = $class_template_result;
if (!$template_types) {
return null;
}

if (!$template_result->template_types) {
$template_result->template_types = $template_types;
}
if (!$class_template_result) {
return new TemplateResult($template_types, []);
}

foreach ($args as $argument_offset => $arg) {
$function_param = null;
$template_result = $class_template_result;

if ($arg->name && $function_storage->allow_named_arg_calls) {
foreach ($function_params as $candidate_param) {
if ($candidate_param->name === $arg->name->name) {
$function_param = $candidate_param;
break;
}
}
} elseif ($argument_offset < count($function_params)) {
$function_param = $function_params[$argument_offset];
} elseif ($last_param && $last_param->is_variadic) {
$function_param = $last_param;
}

if (!$function_param
|| !$function_param->type
) {
continue;
}
if (!$template_result->template_types) {
$template_result->template_types = $template_types;
}

$arg_value_type = $statements_analyzer->node_data->getType($arg->value);
foreach ($args as $argument_offset => $arg) {
$function_param = null;

if (!$arg_value_type) {
continue;
if ($arg->name && $function_storage->allow_named_arg_calls) {
foreach ($function_params as $candidate_param) {
if ($candidate_param->name === $arg->name->name) {
$function_param = $candidate_param;
break;
}
}
} elseif ($argument_offset < count($function_params)) {
$function_param = $function_params[$argument_offset];
} elseif ($last_param && $last_param->is_variadic) {
$function_param = $last_param;
}

$fleshed_out_param_type = \Psalm\Internal\Type\TypeExpander::expandUnion(
$codebase,
$function_param->type,
$class_storage ? $class_storage->name : null,
$calling_class_storage ? $calling_class_storage->name : null,
null,
true,
false,
$calling_class_storage ? $calling_class_storage->final : false
);
if (!$function_param
|| !$function_param->type
) {
continue;
}

TemplateStandinTypeReplacer::replace(
$fleshed_out_param_type,
$template_result,
$codebase,
$statements_analyzer,
$arg_value_type,
$argument_offset,
$context->self,
$context->calling_method_id ?: $context->calling_function_id,
false
);
}
$arg_value_type = $statements_analyzer->node_data->getType($arg->value);

return $template_result;
} else {
return new TemplateResult($template_types, []);
if (!$arg_value_type) {
continue;
}

$fleshed_out_param_type = \Psalm\Internal\Type\TypeExpander::expandUnion(
$codebase,
$function_param->type,
$class_storage ? $class_storage->name : null,
$calling_class_storage ? $calling_class_storage->name : null,
null,
true,
false,
$calling_class_storage ? $calling_class_storage->final : false
);

TemplateStandinTypeReplacer::replace(
$fleshed_out_param_type,
$template_result,
$codebase,
$statements_analyzer,
$arg_value_type,
$argument_offset,
$context->self,
$context->calling_method_id ?: $context->calling_function_id,
false
);
}

return null;
return $template_result;
}

/**
Expand Down

0 comments on commit 1bb8b73

Please sign in to comment.