1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

reworked one known operand case

This commit is contained in:
ebakulin 2023-02-28 00:12:18 +07:00
parent 31fcbd5f69
commit cf35b3ce0c

View File

@ -284,37 +284,19 @@ class ConcatAnalyzer
*/
$known_operand = $right_type ?? $left_type;
$numeric_type = new Union([
new TNumericString,
new TInt,
new TFloat,
]);
if ($known_operand->isSingle()) {
$known_operands_atomic = $known_operand->getSingleAtomic();
$non_empty_string = $numeric_type->getBuilder()->addType(new TNonEmptyString())->freeze();
$non_falsy_string = $numeric_type->getBuilder()->addType(new TNonFalsyString())->freeze();
$known_operand_not_empty = UnionTypeComparator::isContainedBy(
$codebase,
$known_operand,
$non_empty_string,
);
$known_operand_not_falsy = UnionTypeComparator::isContainedBy(
$codebase,
$known_operand,
$non_falsy_string,
);
if ($known_operand_not_empty) {
if ($known_operands_atomic instanceof TNonEmptyString) {
$result_type = Type::getNonEmptyString();
}
if ($known_operand_not_falsy) {
if ($known_operands_atomic instanceof TNonFalsyString) {
$result_type = Type::getNonFalsyString();
}
}
}
}
private static function analyzeOperand(
StatementsAnalyzer $statements_analyzer,