Commit bf249cc
Fix redundant type cast dropping type narrowing in comparisons
- Unwrap redundant cast expressions in Smaller/SmallerOrEqual type specifying
so that narrowing propagates to the inner variable instead of the cast expr
- When a cast produces the same type as its inner expression (e.g. (int) on
an int variable), the narrowing is now applied to the original variable
- New regression test in tests/PHPStan/Analyser/nsrt/bug-7858.php
Closes phpstan/phpstan#78581 parent 5037bd5 commit bf249cc
2 files changed
Lines changed: 46 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
477 | 494 | | |
478 | | - | |
| 495 | + | |
479 | 496 | | |
480 | 497 | | |
481 | | - | |
| 498 | + | |
482 | 499 | | |
483 | 500 | | |
484 | 501 | | |
485 | 502 | | |
486 | 503 | | |
487 | 504 | | |
488 | | - | |
| 505 | + | |
489 | 506 | | |
490 | 507 | | |
491 | | - | |
| 508 | + | |
492 | 509 | | |
493 | 510 | | |
494 | 511 | | |
495 | 512 | | |
496 | 513 | | |
497 | 514 | | |
498 | 515 | | |
499 | | - | |
| 516 | + | |
500 | 517 | | |
501 | 518 | | |
502 | | - | |
| 519 | + | |
503 | 520 | | |
504 | 521 | | |
505 | 522 | | |
506 | 523 | | |
507 | 524 | | |
508 | 525 | | |
509 | | - | |
| 526 | + | |
510 | 527 | | |
511 | 528 | | |
512 | | - | |
| 529 | + | |
513 | 530 | | |
514 | 531 | | |
515 | 532 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments