foreach copy-on-iterate: docs, roadmap, and tests #4

Merged
thesimonharms merged 3 commits from Milo/pic:milo/foreach-copy-docs-and-test into main 2026-10-14 05:54:12 -04:00
Contributor

Follow-up to the merged PR #3 ("foreach: clone array before iteration for copy-on-iterate semantics").

  • README.md: removed the now-false "Dialect: breaking changes" bullet claiming foreach walks the live array without copying first.
  • ROADMAP.md: marked the "Maybe later" item foreach copy-on-iterate as done ([x]), since PR #3 implemented it.
  • internal/compiler/compiler_test.go: added TestForeachCopyOnIterateAppend (appending inside foreach does not affect iteration: 3 iterations, 6 elements afterwards) and TestForeachCopyOnIterateUnset (unsetting an element inside foreach does not affect iteration: all three values 1, 2, 3 are visited), matching real PHP semantics.
Follow-up to the merged PR #3 ("foreach: clone array before iteration for copy-on-iterate semantics"). - README.md: removed the now-false "Dialect: breaking changes" bullet claiming `foreach` walks the live array without copying first. - ROADMAP.md: marked the "Maybe later" item `foreach` copy-on-iterate as done (`[x]`), since PR #3 implemented it. - internal/compiler/compiler_test.go: added `TestForeachCopyOnIterateAppend` (appending inside `foreach` does not affect iteration: 3 iterations, 6 elements afterwards) and `TestForeachCopyOnIterateUnset` (unsetting an element inside `foreach` does not affect iteration: all three values 1, 2, 3 are visited), matching real PHP semantics.
PR #3 changed foreach to clone the array before iterating (copy-on-iterate, matching PHP), so the bullet claiming it walks the live array is now false.
Merged PR #3 implemented it, closing the Maybe later item.
Covers the PR #3 behavior: appending inside foreach does not affect iteration (3 iterations, 6 elements afterwards), and unsetting an element inside foreach does not affect iteration (all three values visited).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thesimonharms/pic!4
No description provided.