mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix inconsistency in partial template matching
This commit is contained in:
parent
5be4cc2582
commit
aca84e6f96
@ -549,15 +549,32 @@ class UnionTemplateHandler
|
||||
}
|
||||
|
||||
if ($add_upper_bound && $input_type) {
|
||||
$matching_input_keys = [];
|
||||
|
||||
if ($codebase
|
||||
&& TypeAnalyzer::isContainedBy(
|
||||
&& TypeAnalyzer::canBeContainedBy(
|
||||
$codebase,
|
||||
$input_type,
|
||||
$replacement_type
|
||||
$replacement_type,
|
||||
false,
|
||||
false,
|
||||
$matching_input_keys
|
||||
)
|
||||
) {
|
||||
$generic_param = clone $input_type;
|
||||
|
||||
if ($matching_input_keys) {
|
||||
$generic_param_keys = \array_keys($generic_param->getAtomicTypes());
|
||||
|
||||
foreach ($generic_param_keys as $atomic_key) {
|
||||
if (!isset($matching_input_keys[$atomic_key])) {
|
||||
$generic_param->removeType($atomic_key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$template_result->template_types[$param_name_key][$atomic_type->defining_class][0]
|
||||
= clone $input_type;
|
||||
= $generic_param;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1133,6 +1133,25 @@ class FunctionTemplateTest extends TestCase
|
||||
'$a' => 'A',
|
||||
]
|
||||
],
|
||||
'possiblyNullMatchesAnotherTemplateType' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-template RealObjectType of object
|
||||
*
|
||||
* @psalm-param class-string<RealObjectType> $className
|
||||
* @psalm-param Closure(
|
||||
* RealObjectType|null
|
||||
* ) : void $initializer
|
||||
*/
|
||||
function createProxy(
|
||||
string $className,
|
||||
Closure $initializer
|
||||
) : void {}
|
||||
|
||||
class Foo {}
|
||||
|
||||
createProxy(Foo::class, function (?Foo $f) : void {});'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user