Skip to content

Commit

Permalink
Bind lower bounds to upper bounds as well when no upper bound can be …
Browse files Browse the repository at this point in the history
…inferred

Ref vimeo#4485
  • Loading branch information
muglug authored and danog committed Jan 29, 2021
1 parent e624f97 commit fb5ee1e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,24 @@ private static function checkFunctionLikeTypeMatches(
$template_result->upper_bounds
[$template_type->param_name]
[$template_type->defining_class]
)
&& !isset(
)) {
if (isset(
$template_result->lower_bounds
[$template_type->param_name]
[$template_type->defining_class]
)
) {
$template_result->upper_bounds[$template_type->param_name][$template_type->defining_class] = [
clone $template_type->as,
0
];
[$template_type->param_name]
[$template_type->defining_class]
)) {
$template_result->upper_bounds[$template_type->param_name][$template_type->defining_class] = [
clone $template_result->lower_bounds
[$template_type->param_name]
[$template_type->defining_class][0],
0
];
} else {
$template_result->upper_bounds[$template_type->param_name][$template_type->defining_class] = [
clone $template_type->as,
0
];
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Template/FunctionTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,29 @@ function($_k, $v) { return (bool) $v; };
})();
}'
],
'allowClosureParamLowerBoundAndUpperBound' => [
'<?php
class Foo {}
/**
* @template TParam as Foo
* @psalm-param Closure(TParam): void $func
* @psalm-return Closure(TParam): TParam
*/
function takesClosure(callable $func): callable {
return
/**
* @psalm-param TParam $value
* @psalm-return TParam
*/
function ($value) use ($func) {
$func($value);
return $value;
};
}
$value = takesClosure(function(Foo $foo) : void {})(new Foo());'
],
];
}

Expand Down

0 comments on commit fb5ee1e

Please sign in to comment.