Skip to content

Commit c737095

Browse files
committed
Division of int ranges produces BenevolentUnionType
1 parent 6e90da1 commit c737095

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Analyser/MutatingScope.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,10 @@ private function integerRangeMath(Type $range, Expr $node, Type $operand): Type
52245224
[$min, $max] = [$max, $min];
52255225
}
52265226

5227+
if ($min === null && $max === null) {
5228+
return new BenevolentUnionType([new IntegerType(), new FloatType()]);
5229+
}
5230+
52275231
return TypeCombinator::union(IntegerRangeType::fromInterval($min, $max), new FloatType());
52285232
}
52295233
}

tests/PHPStan/Analyser/data/div-by-zero.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class Foo
1313
*/
1414
public function doFoo(int $range1, int $range2, int $int): void
1515
{
16-
assertType('float|int', 5 / $range1);
17-
assertType('float|int', 5 / $range2);
16+
assertType('(float|int)', 5 / $range1);
17+
assertType('(float|int)', 5 / $range2);
18+
assertType('(float|int)', $range1 / $range2);
1819
assertType('(float|int)', 5 / $int);
1920
assertType('*ERROR*', 5 / 0);
2021
}

0 commit comments

Comments
 (0)