Skip to content
Permalink
Browse files

Fix #2537 - allow complex intersection templates to be preserved

  • Loading branch information
muglug committed Jan 1, 2020
1 parent d175abe commit 086d141f5c03a2b284f1874ffcdadb33e19d0627
Showing with 32 additions and 8 deletions.
  1. +9 −8 src/Psalm/Internal/Type/UnionTemplateHandler.php
  2. +23 −0 tests/Template/ClassTemplateTest.php
@@ -102,7 +102,8 @@ private static function handleAtomicStandin(
}

if ($atomic_type instanceof Atomic\TTemplateParam
&& isset($template_result->template_types[$atomic_type->param_name][$atomic_type->defining_class])
&& ($param_name_key = strpos($key, '&') ? $key : $atomic_type->param_name)
&& isset($template_result->template_types[$param_name_key][$atomic_type->defining_class])
) {
$a = self::handleTemplateParamStandin(
$atomic_type,
@@ -390,6 +391,12 @@ private static function handleTemplateParamStandin(

$replacement_type = $template_type;

$param_name_key = $atomic_type->param_name;

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

if ($replace) {
$atomic_types = [];

@@ -474,12 +481,6 @@ 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[$param_name_key][$atomic_type->defining_class][0]
)) {
@@ -522,7 +523,7 @@ private static function handleTemplateParamStandin(
$replacement_type
)
) {
$template_result->template_types[$atomic_type->param_name][$atomic_type->defining_class][0]
$template_result->template_types[$param_name_key][$atomic_type->defining_class][0]
= clone $input_type;
}
}
@@ -2219,6 +2219,29 @@ function order(array $collection, callable $sorter): array {
}
}'
],
'intersectOnTOfObject' => [
'<?php
/**
* @psalm-template InterceptedObjectType of object
*/
interface AccessInterceptorInterface
{
/**
* @psalm-param Closure(
* InterceptedObjectType&AccessInterceptorInterface
* ) : mixed $prefixInterceptor
*/
public function setMethodPrefixInterceptor(Closure $prefixInterceptor = null) : void;
}
function foo(AccessInterceptorInterface $i) : void {
$i->setMethodPrefixInterceptor(
function(AccessInterceptorInterface $i) : string {
return "hello";
}
);
}'
]
];
}

0 comments on commit 086d141

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