mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 09:19:40 +01:00
bugfix: overriding types based on assertions have to pass more checks
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
This commit is contained in:
parent
7c85e0c0d9
commit
2d9133b35a
@ -763,7 +763,9 @@ class CallAnalyzer
|
|||||||
$codebase
|
$codebase
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($union->isSingle() || $union->allLiterals()) {
|
$arg_var_type = $context->vars_in_scope[$assertion_var_id];
|
||||||
|
|
||||||
|
if (self::isNewTypeNarrowingDownOldType($arg_var_type, $union)) {
|
||||||
foreach ($union->getAtomicTypes() as $atomic_type) {
|
foreach ($union->getAtomicTypes() as $atomic_type) {
|
||||||
if ($assertion_type instanceof TTemplateParam
|
if ($assertion_type instanceof TTemplateParam
|
||||||
&& $assertion_type->as->getId() === $atomic_type->getId()
|
&& $assertion_type->as->getId() === $atomic_type->getId()
|
||||||
@ -1117,4 +1119,24 @@ class CallAnalyzer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should detect if the new type narrows down the old type.
|
||||||
|
*/
|
||||||
|
private static function isNewTypeNarrowingDownOldType(Union $old_type, Union $new_type): bool
|
||||||
|
{
|
||||||
|
if ($new_type->isSingle()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($old_type->hasMixed() && !$new_type->hasMixed()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($old_type->isSingleAndMaybeNullable() && !$new_type->isNullable()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user