Fix "list type lost in for loop"#4403
Merged
ondrejmirtes merged 2 commits intophpstan:2.1.xfrom Oct 3, 2025
Merged
Conversation
Contributor
Author
|
we could make this work for more involved loops, but I think this will work as a first step -- other examples
|
Collaborator
|
This pull request has been marked as ready for review. |
staabm
commented
Oct 3, 2025
| && $stmt->init[0] instanceof Assign | ||
| && $stmt->init[0]->var instanceof Variable | ||
| && $stmt->init[0]->expr instanceof Node\Scalar\Int_ | ||
| && $stmt->init[0]->expr->value === 0 |
Contributor
Author
There was a problem hiding this comment.
I think we could do >=0
Member
|
Thank you! |
Contributor
Author
|
any opinions on the other given examples? do you think this can work and should be implemented? |
Member
|
Instead of writing many many conditions, I'd like if this could be expressed more by the type system. That would cover all situations. But I'm not sure yet how it could look. |
Contributor
Author
|
ok thanks. no priority on it. |
This was referenced Nov 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
if the for loop is in the shape of
for($i = 0; $i < count($items); $i++) {we can set$items[$i]as existing expression type.closes phpstan/phpstan#12807