Skip to content

Fix #12574: Erroneous Offset might not exist#4988

Merged
staabm merged 15 commits intophpstan:2.1.xfrom
staabm:bug12574
Feb 18, 2026
Merged

Fix #12574: Erroneous Offset might not exist#4988
staabm merged 15 commits intophpstan:2.1.xfrom
staabm:bug12574

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 18, 2026

@phpstan-bot
Copy link
Collaborator

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.

phpstan-bot and others added 13 commits February 18, 2026 13:20
…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
Comment on lines +6812 to +6813
!$expr instanceof PropertyFetch
&& !$expr instanceof ArrayDimFetch
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@staabm staabm changed the base branch from 2.2.x to 2.1.x February 18, 2026 12:48
Copy link
Contributor

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?)

@staabm
Copy link
Contributor Author

staabm commented Feb 18, 2026

The fix is correct, I just wonder if we can fix more situation.

I guess AI will find a fix as soon as someone reports a example :-)

@staabm staabm marked this pull request as ready for review February 18, 2026 13:37
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@VincentLanglet
Copy link
Contributor

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 ?

@staabm
Copy link
Contributor Author

staabm commented Feb 18, 2026

Thanks

@staabm staabm merged commit f844f7b into phpstan:2.1.x Feb 18, 2026
645 of 650 checks passed
@staabm staabm deleted the bug12574 branch February 18, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants