Skip to content
Permalink
Browse files

Improve handling of template params a smidge

  • Loading branch information
muglug committed Dec 27, 2019
1 parent 2f2cd85 commit b78f273ccf635fdac5b21820a022d215a5cb65a3
@@ -99,7 +99,7 @@ private static function handleAtomicStandin(
}

if ($atomic_type instanceof Atomic\TTemplateParam
&& isset($template_result->template_types[$key][$atomic_type->defining_class ?: ''])
&& isset($template_result->template_types[$atomic_type->param_name][$atomic_type->defining_class ?: ''])
) {
$a = self::handleTemplateParamStandin(
$atomic_type,
@@ -371,7 +371,10 @@ private static function handleTemplateParamStandin(
bool $was_nullable,
bool &$had_template
) : array {
$template_type = $template_result->template_types[$key][$atomic_type->defining_class ?: ''][0];
$template_type = $template_result->template_types
[$atomic_type->param_name]
[$atomic_type->defining_class ?: '']
[0];

if ($template_type->getId() === $key) {
return array_values($template_type->getTypes());
@@ -420,7 +423,7 @@ private static function handleTemplateParamStandin(
$atomic_types[] = clone $key_type_atomic;
}

$template_result->generic_params[$key][$atomic_type->defining_class ?: ''][0]
$template_result->generic_params[$atomic_type->param_name][$atomic_type->defining_class ?: ''][0]
= clone $key_type;
}
}
@@ -462,23 +465,32 @@ private static function handleTemplateParamStandin(

$generic_param->setFromDocblock();

if (isset($template_result->generic_params[$key][$atomic_type->defining_class ?: ''][0])) {
$existing_depth = $template_result->generic_params[$key][$atomic_type->defining_class ?: ''][1] ?? -1;
if (isset(
$template_result->generic_params[$atomic_type->param_name][$atomic_type->defining_class ?: ''][0]
)) {
$existing_depth = $template_result->generic_params
[$atomic_type->param_name]
[$atomic_type->defining_class ?: '']
[1]
?? -1;

if ($existing_depth > $depth) {
return $atomic_types ?: [$atomic_type];
}

if ($existing_depth === $depth) {
$generic_param = \Psalm\Type::combineUnionTypes(
$template_result->generic_params[$key][$atomic_type->defining_class ?: ''][0],
$template_result->generic_params
[$atomic_type->param_name]
[$atomic_type->defining_class ?: '']
[0],
$generic_param,
$codebase
);
}
}

$template_result->generic_params[$key][$atomic_type->defining_class ?: ''] = [
$template_result->generic_params[$atomic_type->param_name][$atomic_type->defining_class ?: ''] = [
$generic_param,
$depth,
];
@@ -495,7 +507,8 @@ private static function handleTemplateParamStandin(
$replacement_type
)
) {
$template_result->template_types[$key][$atomic_type->defining_class ?: ''][0] = clone $input_type;
$template_result->template_types[$atomic_type->param_name][$atomic_type->defining_class ?: ''][0]
= clone $input_type;
}
}

@@ -52,7 +52,7 @@ public function getKey()
return $this->param_name . '&' . implode('&', $this->extra_types);
}

return $this->param_name;
return $this->param_name . ($this->defining_class ? ':' . $this->defining_class : '');
}

/**
@@ -618,6 +618,7 @@ public function getType()
*/
public function bar(Foo $object) : void
{
/** @psalm-suppress RedundantConditionGivenDocblockType */
if ($this->getType() !== get_class($object)) {
return;
}

0 comments on commit b78f273

Please sign in to comment.
You can’t perform that action at this time.