Repository navigation
Commit dc636ee
Detect overflowing
- `integerRangeMath()` computed `<<` bounds with a wrapping shift, so an overflowing shift
produced an inverted range (`int<1, 2> << 62` was `*NEVER*`) or an unsound one
(`int<1, 3> << 63` claimed `-9223372036854775808`, but `2 << 63` is `0`). Overflow is now
detected with a shift round-trip and falls back to `int`. `>>` is arithmetic and cannot
overflow, so it is left alone.
- `getDivType()` removed `float` from the result whenever the modulo was `0`, which turned
`(PHP_INT_MIN) / -1` into `*NEVER*` because that result is float-only. The removal is now
skipped when it would leave `never`.
- `getModType()` reads both operands' bounds through `toInteger()`, matching what `%` does
at runtime, so `%` on non-integer numeric operands is bounded too (`float % 2.4` is
`int<-1, 1>`). A divisor that truncates to `0` (`$f % 0.5`) still yields an unbounded
result instead of `*NEVER*`.
`bug-15242.php` also gains the remaining `%` cases probed for phpstan/phpstan#15242
(non-positive dividends, `PHP_INT_MAX` divisors, negative constant unions, `%=`), which
already pass and stay as regression coverage.
Probed and found already correct: `abs()` / `toAbsoluteNumber()` (already guards
`PHP_INT_MIN`), `IntdivThrowTypeExtension` (already models `PHP_INT_MIN / -1`),
`toBitwiseNotType()`, and the bitwise and/or/xor range helpers.<< bounds, keep float for PHP_INT_MIN / -1, and bound % on non-integer operands1 parent 2faa295 commit dc636ee
3 files changed
Lines changed: 101 additions & 9 deletions
File tree
- src/Reflection
- tests/PHPStan/Analyser/nsrt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1328 | 1328 | | |
1329 | 1329 | | |
1330 | 1330 | | |
1331 | | - | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
1332 | 1337 | | |
1333 | 1338 | | |
1334 | 1339 | | |
| |||
1456 | 1461 | | |
1457 | 1462 | | |
1458 | 1463 | | |
1459 | | - | |
1460 | | - | |
1461 | | - | |
1462 | | - | |
1463 | | - | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
1464 | 1467 | | |
1465 | 1468 | | |
1466 | | - | |
| 1469 | + | |
1467 | 1470 | | |
1468 | 1471 | | |
1469 | 1472 | | |
| |||
1510 | 1513 | | |
1511 | 1514 | | |
1512 | 1515 | | |
1513 | | - | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
1514 | 1522 | | |
1515 | 1523 | | |
1516 | 1524 | | |
| |||
2606 | 2614 | | |
2607 | 2615 | | |
2608 | 2616 | | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
2609 | 2625 | | |
2610 | 2626 | | |
2611 | 2627 | | |
| |||
2631 | 2647 | | |
2632 | 2648 | | |
2633 | 2649 | | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
2634 | 2659 | | |
2635 | 2660 | | |
2636 | 2661 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
| 313 | + | |
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
0 commit comments