Skip to content
Permalink
Browse files

Improve templating for intersections

  • Loading branch information
muglug committed Jan 1, 2020
1 parent 4630d19 commit d175abe0f0ee15df185846a02c8de93387619b48
Showing with 11 additions and 5 deletions.
  1. +10 −4 src/Psalm/Internal/Type/UnionTemplateHandler.php
  2. +1 −1 src/Psalm/Type/Atomic/TTemplateParam.php
@@ -474,11 +474,17 @@ private static function handleTemplateParamStandin(

$generic_param->setFromDocblock();

$param_name_key = $atomic_type->param_name;

if (strpos($key, '&')) {
$param_name_key = $key;
}

if (isset(
$template_result->generic_params[$atomic_type->param_name][$atomic_type->defining_class][0]
$template_result->generic_params[$param_name_key][$atomic_type->defining_class][0]
)) {
$existing_depth = $template_result->generic_params
[$atomic_type->param_name]
[$param_name_key]
[$atomic_type->defining_class]
[1]
?? -1;
@@ -490,7 +496,7 @@ private static function handleTemplateParamStandin(
if ($existing_depth === $depth) {
$generic_param = \Psalm\Type::combineUnionTypes(
$template_result->generic_params
[$atomic_type->param_name]
[$param_name_key]
[$atomic_type->defining_class]
[0],
$generic_param,
@@ -499,7 +505,7 @@ private static function handleTemplateParamStandin(
}
}

$template_result->generic_params[$atomic_type->param_name][$atomic_type->defining_class] = [
$template_result->generic_params[$param_name_key][$atomic_type->defining_class] = [
$generic_param,
$depth,
];
@@ -49,7 +49,7 @@ public function __toString()
public function getKey()
{
if ($this->extra_types) {
return $this->param_name . '&' . implode('&', $this->extra_types);
return $this->param_name . ':' . $this->defining_class . '&' . implode('&', $this->extra_types);
}

return $this->param_name . ':' . $this->defining_class;

0 comments on commit d175abe

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