Commit 12edc22
Fix phpstan/phpstan#14311: nullsafe.neverNull false positive when object can be null
- In IssetCheck, the nullsafe.neverNull error was reported unconditionally for
NullsafePropertyFetch inside ??, isset(), and empty(), without checking if the
left side of ?-> could actually be null
- Added a check on $expr->var's type before reporting the error, consistent with
how NullsafePropertyFetchRule already handles this
- Updated test expectations for bug-7109 in NullCoalesceRuleTest, IssetRuleTest,
and EmptyRuleTest to remove false positive expectations
- New regression test in tests/PHPStan/Rules/Variables/data/bug-14311.php1 parent 6bac0de commit 12edc22
5 files changed
Lines changed: 38 additions & 40 deletions
File tree
- src/Rules
- tests/PHPStan/Rules/Variables
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | 118 | | |
127 | 119 | | |
128 | 120 | | |
129 | 121 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | 122 | | |
135 | 123 | | |
136 | 124 | | |
137 | 125 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | 126 | | |
143 | 127 | | |
144 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | 336 | | |
345 | 337 | | |
346 | 338 | | |
347 | 339 | | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | 340 | | |
353 | 341 | | |
354 | 342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | 256 | | |
265 | 257 | | |
266 | 258 | | |
267 | 259 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | 260 | | |
273 | 261 | | |
274 | 262 | | |
| |||
377 | 365 | | |
378 | 366 | | |
379 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
380 | 374 | | |
| 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 | + | |
0 commit comments