File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -1335,8 +1335,8 @@ private function resolveType(Expr $node): Type
13351335 $ min = $ leftMin !== null && $ rightMin !== null ? $ leftMin * $ rightMin : null ;
13361336 $ max = $ leftMax !== null && $ rightMax !== null ? $ leftMax * $ rightMax : null ;
13371337 } else {
1338- $ min = $ leftMin !== null && $ rightMin !== null ? (int ) ($ leftMin / $ rightMin ) : null ;
1339- $ max = $ leftMax !== null && $ rightMax !== null ? (int ) ($ leftMax / $ rightMax ) : null ;
1338+ $ min = $ leftMin !== null && $ rightMin !== null && $ rightMin !== 0 ? (int ) ($ leftMin / $ rightMin ) : null ;
1339+ $ max = $ leftMax !== null && $ rightMax !== null && $ rightMax !== 0 ? (int ) ($ leftMax / $ rightMax ) : null ;
13401340
13411341 if ($ min !== null && $ max !== null && $ min > $ max ) {
13421342 [$ min , $ max ] = [$ max , $ min ];
Original file line number Diff line number Diff line change @@ -485,6 +485,8 @@ public function dataFileAsserts(): iterable
485485 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-5529.php ' );
486486
487487 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/sizeof.php ' );
488+
489+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/div-by-zero.php ' );
488490 }
489491
490492 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace DivByZero ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ class Foo
8+ {
9+
10+ /**
11+ * @param int<0, max> $range1
12+ * @param int<min, 0> $range2
13+ */
14+ public function doFoo (int $ range1 , int $ range2 ): void
15+ {
16+ assertType ('(float|int) ' , 5 / $ range1 );
17+ assertType ('(float|int) ' , 5 / $ range2 );
18+ assertType ('*ERROR* ' , 5 / 0 );
19+ }
20+
21+ }
You can’t perform that action at this time.
0 commit comments