You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c3389dc
Browse filesBrowse the repository at this point in the historyBrowse files
Narrow foreach body to non-empty behind an opt-in toggle
Inside a foreach body the iterated expression is provably non-empty, so it
can be narrowed (list to non-empty-list, array to non-empty-array) at body
entry. Before, this happened only when polluteScopeWithAlwaysIterableForeach
was on, so with the flag off (as phpstan-strict-rules sets it) the narrowing
disappeared even though the body is only entered when the iteratee is
non-empty.
The narrowing is gated behind the new feature toggle narrowForeachBodyNonEmpty,
off by default. With it off the body scope is built exactly as before, so no
behaviour changes. With it on, the body narrows regardless of the flag.
Narrowing the body also feeds the loop-exit scope, which with the flag off
must stay conservative: it must not conclude the loop always iterated. After
the body pass the iterated expression's possibly-empty-ness is restored in the
after-loop scope, keeping any element types the body refined. This containment
is partial: definedness that flows through variables the body builds (rather
than through the iterated expression itself) still reaches the after-loop
scope. Because of that residual, the toggle is not enabled under bleedingEdge
yet; it is opt-in until the leak is fully contained.
Closesphpstan/phpstan#13312
0 commit comments