Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use last for condition to filter scope #3578

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Oct 18, 2024

Improves phpstan/phpstan#11872 but does not exactly what I hope would be possible. But with the way things currently work (going through conditions and filtering the scope) this might just not be achievable or worth it. So less precise type is better than more precise type that is wrong for me tbh :)

@herndlm herndlm changed the base branch from 2.0.x to 1.12.x October 18, 2024 20:05
@herndlm herndlm force-pushed the for-filter-last-part branch from e307931 to 7ce175e Compare October 18, 2024 20:06
@herndlm herndlm marked this pull request as draft October 18, 2024 20:21
@herndlm herndlm force-pushed the for-filter-last-part branch 3 times, most recently from e7479d7 to 2273a46 Compare October 18, 2024 21:11
@herndlm herndlm marked this pull request as ready for review October 18, 2024 21:20
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm herndlm force-pushed the for-filter-last-part branch from 2273a46 to 142e734 Compare October 18, 2024 21:23
@herndlm herndlm force-pushed the for-filter-last-part branch from 142e734 to 7c587ab Compare October 23, 2024 14:43
@ondrejmirtes
Copy link
Member

Can you explain the PHP behaviour here like I'm five? :) I don't get what's going on.

@herndlm
Copy link
Contributor Author

herndlm commented Nov 5, 2024

I think the main thing is that (see https://www.php.net/manual/en/control-structures.for.php) all cond (expr2) expressions are executed, but only the last one is used to determine if the loop should continue. Based on that it doesn't make sense (to me at least ;)) to filter the scope by any other than the last expression to narrow types.

UPDATE: having said that and while that makes sense to me, I'm not a 100% sure anymore if I adapted the right places here..

@ondrejmirtes ondrejmirtes merged commit 13798c2 into phpstan:1.12.x Nov 6, 2024
451 checks passed
@ondrejmirtes
Copy link
Member

Alright, thank you!

@herndlm herndlm deleted the for-filter-last-part branch November 6, 2024 10:07
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.

None yet

3 participants