1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

refine Mod with positives everywhere

This commit is contained in:
orklah 2021-09-16 19:33:57 +02:00
parent f87bd56105
commit 25f78b5d54

View File

@ -1326,7 +1326,14 @@ class ArithmeticOpAnalyzer
}
} elseif ($right_type_part->isPositive()) {
if ($left_type_part->isPositiveOrZero()) {
$new_result_type = new Type\Union([new TIntRange(0, null)]);
if ($left_type_part->max_bound !== null) {
//we now that the result will be a range between 0 and $left->max - 1
$new_result_type = new Type\Union(
[new TIntRange(0, $left_type_part->max_bound - 1)]
);
} else {
$new_result_type = new Type\Union([new TIntRange(0, null)]);
}
} elseif ($left_type_part->isNegativeOrZero()) {
$new_result_type = new Type\Union([new TIntRange(null, 0)]);
} else {