Commit 45c195a
committed
Fix TypeError dead catch false positive when assigning mixed to typed property
- Changed property assignment TypeError throw point check from accepts() to isSuperTypeOf() using native types
- MixedType::isAcceptedBy() always returns yes, causing accepts() to miss that mixed-to-int can throw TypeError
- Using isSuperTypeOf() on native types correctly identifies mixed as not guaranteed to be compatible
- Widened property type check to include int when property type contains float, preserving PHP's int-to-float coercion
- Added regression test with final classes to verify behavior independent of property hooks
Closes phpstan/phpstan#91461 parent 106fc93 commit 45c195a
File tree
3 files changed
+54
-1
lines changed- src/Analyser
- tests/PHPStan/Rules/Exceptions
- data
3 files changed
+54
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6366 | 6366 | | |
6367 | 6367 | | |
6368 | 6368 | | |
| 6369 | + | |
| 6370 | + | |
| 6371 | + | |
| 6372 | + | |
| 6373 | + | |
| 6374 | + | |
6369 | 6375 | | |
6370 | | - | |
| 6376 | + | |
6371 | 6377 | | |
6372 | 6378 | | |
6373 | 6379 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
646 | 651 | | |
| 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 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
0 commit comments