Fix #12574: Erroneous Offset might not exist#4988
Conversation
|
You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x. |
…operty 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#12574
Closes phpstan/phpstan#11870 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Closes phpstan/phpstan#11102 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Closes phpstan/phpstan#10040 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Closes phpstan/phpstan#7716 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Closes phpstan/phpstan#6991 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Closes phpstan/phpstan#6120 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-authored-by: Markus Staab <[email protected]>
This reverts commit a538aa4. Co-authored-by: Markus Staab <[email protected]>
| !$expr instanceof PropertyFetch | ||
| && !$expr instanceof ArrayDimFetch |
There was a problem hiding this comment.
I started thinking about whether we need to verify the $expr's *Fetch does not reference the $variableName - similar to how it happens above for $expr instanceof Variable.
did not yet find a case in which it makes a difference
VincentLanglet
left a comment
There was a problem hiding this comment.
The fix is correct, I just wonder if we can fix more situation.
I added test suggestion if you think they are worth it.
(You let this PR in draft ?)
I guess AI will find a fix as soon as someone reports a example :-) |
|
This pull request has been marked as ready for review. |
|
You added a lot of non regression test related to some issues ; you need to update the PR description to tell which ones are fixed, no ? |
|
Thanks |
Fixes phpstan/phpstan#12574
Closes phpstan/phpstan#10040
Closes phpstan/phpstan#11102
Closes phpstan/phpstan#11870
Closes phpstan/phpstan#6991
Closes phpstan/phpstan#7716