Repository navigation
Conversation
…rminate When every unrolled iteration of a constant-array foreach ends in return or throw (for example a loop that returns for each enum case), no iteration reaches the back edge and the unrolled end scope was null. ForeachHandler then used the scope of the generic final pass, so the code after the loop saw the subject with its full type instead of never. The unrolled processing now uses the end scope of the terminating iteration when the loop has no other exit. This restores the 2.2 behaviour, which 003d601 changed.
…rminate in turbo-ext Port cfd7d138b to the native ForeachHandler. The native tryProcessUnrolledConstantArrayForeach() now collects the scope of each iteration that terminates. When the loop has no chain scope and no break scope, it merges these scopes into the end scope, in the same order as the PHP twin.
janedbal
marked this pull request as ready for review
October 9, 2026 11:10
Collaborator
|
This pull request has been marked as ready for review. |
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.
Closes phpstan/phpstan#15390
A
foreachover a constant array that returns for every value no longer narrows the subject after the loop. This is a regression in 2.3.0 from 003d601 (#6420).When every unrolled iteration terminates, the unrolled processing sets the chain scope to
null. Without abreak, the end scope staysnullandForeachHandleruses the scope of the generic final pass. That scope holds the subject with its full type.ForeachHandlernow collects the end scope of each iteration that terminates. It merges these scopes into the end scope when the loop has no other exit.turbo-ext/src/ForeachHandler.cppgets the same change.tests/PHPStan/Analyser/nsrt/bug-15390.phpis the regression test. It fails without the change inForeachHandler.phpand passes with it.— Claude