Commit a939250
committed
Fix phpstan/phpstan#14227: Variable might not be defined false positive with unset in mutually exclusive branch
- Added preserveSafeConditionalExpressions() to MutatingScope to preserve conditional
expressions through merges when one branch invalidates a variable (e.g. via unset())
but the guard condition is disjoint from the other branch's types
- This also fixes related false positives for variables defined in different branches of
if/elseif/else (bug-4173, dynamic-access test improvements)
- Restricted preservation to simple Variable expressions to avoid stale method call narrowing
- New regression test in tests/PHPStan/Rules/Variables/data/bug-14227.php1 parent 0c740e3 commit a939250
File tree
3 files changed
+124
-24
lines changed- src/Analyser
- tests/PHPStan/Rules/Variables
- data
3 files changed
+124
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3952 | 3952 | | |
3953 | 3953 | | |
3954 | 3954 | | |
| 3955 | + | |
| 3956 | + | |
3955 | 3957 | | |
3956 | 3958 | | |
3957 | 3959 | | |
| |||
4051 | 4053 | | |
4052 | 4054 | | |
4053 | 4055 | | |
| 4056 | + | |
| 4057 | + | |
| 4058 | + | |
| 4059 | + | |
| 4060 | + | |
| 4061 | + | |
| 4062 | + | |
| 4063 | + | |
| 4064 | + | |
| 4065 | + | |
| 4066 | + | |
| 4067 | + | |
| 4068 | + | |
| 4069 | + | |
| 4070 | + | |
| 4071 | + | |
| 4072 | + | |
| 4073 | + | |
| 4074 | + | |
| 4075 | + | |
| 4076 | + | |
| 4077 | + | |
| 4078 | + | |
| 4079 | + | |
| 4080 | + | |
| 4081 | + | |
| 4082 | + | |
| 4083 | + | |
| 4084 | + | |
| 4085 | + | |
| 4086 | + | |
| 4087 | + | |
| 4088 | + | |
| 4089 | + | |
| 4090 | + | |
| 4091 | + | |
| 4092 | + | |
| 4093 | + | |
| 4094 | + | |
| 4095 | + | |
| 4096 | + | |
| 4097 | + | |
| 4098 | + | |
| 4099 | + | |
| 4100 | + | |
| 4101 | + | |
| 4102 | + | |
| 4103 | + | |
| 4104 | + | |
| 4105 | + | |
| 4106 | + | |
| 4107 | + | |
| 4108 | + | |
| 4109 | + | |
| 4110 | + | |
| 4111 | + | |
| 4112 | + | |
| 4113 | + | |
| 4114 | + | |
| 4115 | + | |
| 4116 | + | |
| 4117 | + | |
| 4118 | + | |
| 4119 | + | |
| 4120 | + | |
| 4121 | + | |
| 4122 | + | |
| 4123 | + | |
| 4124 | + | |
4054 | 4125 | | |
4055 | 4126 | | |
4056 | 4127 | | |
| |||
Lines changed: 18 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | | - | |
| 914 | + | |
920 | 915 | | |
921 | 916 | | |
922 | 917 | | |
| |||
1119 | 1114 | | |
1120 | 1115 | | |
1121 | 1116 | | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
| 1117 | + | |
1131 | 1118 | | |
1132 | 1119 | | |
1133 | 1120 | | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
| 1121 | + | |
1139 | 1122 | | |
1140 | 1123 | | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | 1124 | | |
1146 | 1125 | | |
1147 | 1126 | | |
| |||
1400 | 1379 | | |
1401 | 1380 | | |
1402 | 1381 | | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
1403 | 1397 | | |
| 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 | + | |
0 commit comments