Skip to content

Commit cc6d89c

Browse files
authored
IntegerRangeMath: cover more maxima cases
1 parent ba3f7ed commit cc6d89c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Analyser/MutatingScope.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5300,6 +5300,15 @@ private function integerRangeMath(Type $range, Expr $node, Type $operand): Type
53005300
$max = $rangeMax !== null && $operand->getMax() !== null && $operand->getMax() !== 0 ? $rangeMax / $operand->getMax() : null;
53015301
}
53025302

5303+
if ($range instanceof IntegerRangeType && $operand instanceof IntegerRangeType) {
5304+
if ($rangeMax === null && $operand->getMax() === null) {
5305+
$min = 0;
5306+
} elseif ($rangeMin === null && $operand->getMin() === null) {
5307+
$min = null;
5308+
$max = null;
5309+
}
5310+
}
5311+
53035312
if ($operand instanceof IntegerRangeType
53045313
&& ($operand->getMin() === null || $operand->getMax() === null)
53055314
|| ($rangeMin === null || $rangeMax === null)

tests/PHPStan/Analyser/data/integer-range-types.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ public function math($i, $j, $z, $pi, $r1, $r2, $r3, $rMin, $rMax, $x, $y) {
281281

282282
assertType('5|10|15|20|30', $x / $y);
283283

284+
assertType('float|int<0, max>', $rMax / $rMax);
285+
assertType('(float|int)', $rMin / $rMin);
286+
}
287+
288+
/**
289+
* @param int<0, max> $a
290+
* @param int<0, max> $b
291+
*/
292+
function divisionLoosesInformation(int $a, int $b): void {
293+
assertType('float|int<0, max>',$a/$b);
284294
}
285295

286296
/**

0 commit comments

Comments
 (0)