mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Bind lower bounds to upper bounds as well when no upper bound can be inferred
Ref #4485
This commit is contained in:
parent
a8d7248c31
commit
2f7bf2a144
@ -307,17 +307,24 @@ class ArgumentAnalyzer
|
||||
$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
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1421,6 +1421,29 @@ class FunctionTemplateTest extends TestCase
|
||||
})();
|
||||
}'
|
||||
],
|
||||
'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());'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user