Skip to content

Set/Map forEach with mid-iteration delete visits holes and skips entries (gap test red on main) #9072

Description

@proggeramlug

test-files/test_gap_set_map_foreach_fused_receiver.ts fails on clean main — cases 5–7 (delete during Set.prototype.forEach / Map.prototype.forEach) return wrong elements, and test-parity/gap_snapshot.json expects the test to pass, so any full gap run is red on it.

Node 26.5.1 (pinned oracle):

[1,2] 0
["a:1","b:2","c:3"] 0
["p","q","r"] 2

Perry (both main @ 86c910471 and a current feature branch, perry-dev builds, PERRY_NO_AUTO_OPTIMIZE=1 — byte-identical on both arms, so pre-existing):

[1,null] 1
["a:1","NaN:undefined","b:2"] 1
["p","q"] 2

The shape is exactly what the test's own header warns about: delete during forEach used to compact the backing vector and was fixed for that; the current failure smells like the tombstone-hole delete work (#9020 Map pattern / recent Set-Map hole handling) changed delete-during-iteration bookkeeping — [1,null] (a hole surfaced to the callback), NaN:undefined (a hole key/value pair visited), and a stale size of 1 after deleting both entries. Case 7 additionally skips "r" after deleting an earlier entry.

Found while running the full gap suite for #9066 on 2026-08-29; A/B'd from the merge-base before attributing (both arms identical, so it is not from that PR).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions