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
1335
1335
$ min = $ leftMin !== null && $ rightMin !== null ? $ leftMin * $ rightMin : null ;
1336
1336
$ max = $ leftMax !== null && $ rightMax !== null ? $ leftMax * $ rightMax : null ;
1337
1337
} 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 ;
1340
1340
1341
1341
if ($ min !== null && $ max !== null && $ min > $ max ) {
1342
1342
[$ min , $ max ] = [$ max , $ min ];
Original file line number Diff line number Diff line change @@ -485,6 +485,8 @@ public function dataFileAsserts(): iterable
485
485
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-5529.php ' );
486
486
487
487
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/sizeof.php ' );
488
+
489
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/div-by-zero.php ' );
488
490
}
489
491
490
492
/**
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