Commit 86a07a2
committed
Fix isset() type narrowing lost when result stored in variable for property access
- Extended processSureTypesForConditionalExpressionsAfterAssign and
processSureNotTypesForConditionalExpressionsAfterAssign to store conditional
expressions for PropertyFetch, ArrayDimFetch, and StaticPropertyFetch in
addition to Variable expressions
- Previously, when `$notEmpty = isset($a->worlds[0])` was used in a condition
like `if ($notEmpty && $a->worlds[0]->x === 1)`, the type narrowing for
`$a->worlds` (HasOffsetType) was discarded because only Variable expressions
were stored as conditional expressions
- New regression test in tests/PHPStan/Rules/Arrays/data/bug-12574c.php
Closes phpstan/phpstan#125741 parent 106fc93 commit 86a07a2
File tree
3 files changed
+63
-14
lines changed- src/Analyser
- tests/PHPStan/Rules/Arrays
- data
3 files changed
+63
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6776 | 6776 | | |
6777 | 6777 | | |
6778 | 6778 | | |
6779 | | - | |
6780 | | - | |
6781 | | - | |
6782 | | - | |
6783 | | - | |
6784 | | - | |
| 6779 | + | |
| 6780 | + | |
| 6781 | + | |
| 6782 | + | |
6785 | 6783 | | |
6786 | | - | |
| 6784 | + | |
| 6785 | + | |
| 6786 | + | |
| 6787 | + | |
| 6788 | + | |
| 6789 | + | |
| 6790 | + | |
| 6791 | + | |
6787 | 6792 | | |
6788 | 6793 | | |
6789 | 6794 | | |
| |||
6810 | 6815 | | |
6811 | 6816 | | |
6812 | 6817 | | |
6813 | | - | |
6814 | | - | |
6815 | | - | |
6816 | | - | |
6817 | | - | |
6818 | | - | |
| 6818 | + | |
| 6819 | + | |
| 6820 | + | |
| 6821 | + | |
6819 | 6822 | | |
6820 | | - | |
| 6823 | + | |
| 6824 | + | |
| 6825 | + | |
| 6826 | + | |
| 6827 | + | |
| 6828 | + | |
| 6829 | + | |
| 6830 | + | |
6821 | 6831 | | |
6822 | 6832 | | |
6823 | 6833 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1038 | 1038 | | |
1039 | 1039 | | |
1040 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
1041 | 1048 | | |
1042 | 1049 | | |
1043 | 1050 | | |
| |||
| 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 | + | |
0 commit comments