mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #1680 - narrow nullable templated matching
This commit is contained in:
parent
0bcf61dee7
commit
052599192a
@ -1009,10 +1009,16 @@ class Union
|
||||
|
||||
if ($input_type) {
|
||||
$generic_param = clone $input_type;
|
||||
|
||||
if ($this->isNullable() && $generic_param->isNullable()) {
|
||||
$generic_param->removeType('null');
|
||||
}
|
||||
|
||||
$generic_param->setFromDocblock();
|
||||
|
||||
if (isset($generic_params[$key][$atomic_type->defining_class ?: ''][0])) {
|
||||
$existing_depth = $generic_params[$key][$atomic_type->defining_class ?: ''][1] ?? -1;
|
||||
|
||||
if ($existing_depth > $depth) {
|
||||
continue;
|
||||
}
|
||||
|
@ -2572,6 +2572,28 @@ class TemplateTest extends TestCase
|
||||
return get(B::class, $mapB, $id);
|
||||
}'
|
||||
],
|
||||
'dontGeneraliseBoundParamWithWiderCallable' => [
|
||||
'<?php
|
||||
class C {
|
||||
public function foo() : void {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-template T
|
||||
* @psalm-param T $t
|
||||
* @psalm-param callable(?T):void $callable
|
||||
* @return T
|
||||
*/
|
||||
function makeConcrete($t, callable $callable) {
|
||||
$callable(rand(0, 1) ? $t : null);
|
||||
return $t;
|
||||
}
|
||||
|
||||
$c = makeConcrete(new C(), function (?C $c) : void {});',
|
||||
[
|
||||
'$c' => 'C',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user