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 90d4a7d
Browse filesBrowse the repository at this point in the historyBrowse files
Narrow foreach body to non-empty regardless of polluteScopeWithAlwaysIterableForeach
Inside a foreach body the iterated expression is provably non-empty, so it
is narrowed (list -> non-empty-list, array -> non-empty-array) at body entry.
Previously this only happened when polluteScopeWithAlwaysIterableForeach was
on, so with the flag off (as phpstan-strict-rules sets it) the narrowing
silently disappeared even though the body is only entered when the iteratee
is non-empty.
The narrowing is now applied to the body scope unconditionally. To keep the
flag's contract intact, the narrowing must not leak past the loop: with the
flag off we must not conclude the loop always iterated. After the body pass
the iterated expression's possibly-empty-ness is therefore restored in the
after-loop scope (keeping any element types the body refined), so the
loop-exit merge forms the same conservative scope as before -- in particular
it must not decide the value variable is always defined after the loop. Only
the non-emptiness the narrowing itself introduced is stripped: an iteratee
that was already provably non-empty before the loop keeps that property.
Closesphpstan/phpstan#13312
0 commit comments