From 25f78b5d54307c8dd35951bdba902c37e2d2ab02 Mon Sep 17 00:00:00 2001 From: orklah Date: Thu, 16 Sep 2021 19:33:57 +0200 Subject: [PATCH] refine Mod with positives everywhere --- .../Expression/BinaryOp/ArithmeticOpAnalyzer.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php index 0ff97b902..0277e566c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/ArithmeticOpAnalyzer.php @@ -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 {