1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Change evaluation order of conditionals

This commit is contained in:
Brown 2020-04-14 21:07:16 -04:00
parent e4bfe9e6be
commit fbe0669921
3 changed files with 25 additions and 2 deletions

View File

@ -160,7 +160,5 @@ class TConditional extends \Psalm\Type\Atomic
?Codebase $codebase
) : void {
$this->conditional_type->replaceTemplateTypesWithArgTypes($template_result, $codebase);
$this->if_type->replaceTemplateTypesWithArgTypes($template_result, $codebase);
$this->else_type->replaceTemplateTypesWithArgTypes($template_result, $codebase);
}
}

View File

@ -11,6 +11,11 @@ class TNumericString extends TString
return 'numeric-string';
}
public function __toString()
{
return 'numeric-string';
}
public function getId(bool $nested = false)
{
return $this->getKey();

View File

@ -1321,6 +1321,10 @@ class Union implements TypeNode
$atomic_type->conditional_type
)) {
$class_template_type = clone $atomic_type->if_type;
$class_template_type->replaceTemplateTypesWithArgTypes(
$template_result,
$codebase
);
} elseif (TypeAnalyzer::isContainedBy(
$codebase,
$template_type,
@ -1333,10 +1337,24 @@ class Union implements TypeNode
)
) {
$class_template_type = clone $atomic_type->else_type;
$class_template_type->replaceTemplateTypesWithArgTypes(
$template_result,
$codebase
);
}
}
if (!$class_template_type) {
$atomic_type->if_type->replaceTemplateTypesWithArgTypes(
$template_result,
$codebase
);
$atomic_type->else_type->replaceTemplateTypesWithArgTypes(
$template_result,
$codebase
);
$class_template_type = Type::combineUnionTypes(
$atomic_type->if_type,
$atomic_type->else_type,
@ -1385,6 +1403,8 @@ class Union implements TypeNode
$atomic_types,
$codebase
)->getAtomicTypes();
$this->id = null;
}
}