Skip to content

Thread the foreach iteratee type; resolve intertwined by-ref slots from the root type - #6162

Merged
ondrejmirtes merged 2 commits into
2.2.xfrom
extract-foreach-intertwined
Jul 31, 2026
Merged

Thread the foreach iteratee type; resolve intertwined by-ref slots from the root type#6162
ondrejmirtes merged 2 commits into
2.2.xfrom
extract-foreach-intertwined

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Two more branch-agnostic extractions from the resolve-type-rewrite branch:

  • MutatingScope::enterForeach()/enterForeachKey() take the iteratee type and its native flavour from the caller. The foreach handling computes the pair once per position (entry scope, then the non-empty-narrowed scope) and threads it through NodeScopeResolver::enterForeach() and tryProcessUnrolledConstantArrayForeach(), instead of every scope-enter helper re-pricing $stmt->expr.
  • The intertwined by-ref slot propagation resolves the slot's new value by walking the offsets from the just-assigned root variable type (resolveIntertwinedAssignedType()), instead of re-evaluating the stored assigned expression through Scope::getType() — the stored ArrayDimFetch captured the array variable before it existed, so re-reading resolves through the asking scope rather than the authoritative just-assigned value.

All suites pass unchanged: NodeScopeResolverTest 1694, full suite 17811, make phpstan, make cs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DaBZjgksga4c5s6Q9FniY7

ondrejmirtes and others added 2 commits July 31, 2026 14:09
The foreach handling already holds the iteratee type where these are
called - computed once per position instead of re-priced inside every
scope-enter helper.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DaBZjgksga4c5s6Q9FniY7
Walk the offsets from the root variable type instead of re-evaluating
the stored assigned expression via Scope::getType() - the stored
ArrayDimFetch captured the array variable before it existed, so
re-reading it resolves through the asking scope instead of the
authoritative just-assigned value.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DaBZjgksga4c5s6Q9FniY7
@ondrejmirtes
ondrejmirtes merged commit 70ef67f into 2.2.x Jul 31, 2026
742 of 744 checks passed
@ondrejmirtes
ondrejmirtes deleted the extract-foreach-intertwined branch July 31, 2026 12:18
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.

1 participant