Carry a block's next value through flat_map#1544
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the code generator in src/codegen_fold.c to correctly handle next statements with array values inside flat_map blocks. Specifically, it introduces a forward declaration for emit_block_value_into and uses it within emit_flat_map_expr to collect the block's next-aware value into a temporary array variable, ensuring that next [..] flattens its array like the tail expression. It also adds corresponding test cases and expected outputs. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
flat_map evaluated the block's array as a plain tail expression, so a `next [..]` inside the block was lowered to a bare `continue` and lost. Fill the per-iteration array temp through the shared `emit_block_value_into` helper (initialized to its type default) before splatting its elements into the result, so a `next [..]` flattens its array just like the tail does. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d37d318 to
334b052
Compare
Summary
flat_mapevaluated the block's array as a plain tail expression, so anext [..]inside the block was lowered to a barecontinueand lost.This mirrors the array
map/select/rejectpaths, which already route the block value through the next-aware helper.Implementation
Fill the per-iteration array temp through the shared
emit_block_value_intohelper (initialized to its type default) before splatting its elements into the result — so anext [..]flattens its array exactly like the tail expression does. The forward declaration ofemit_block_value_intomoves to the top of the file soemit_flat_map_expr(above the definition) can see it.Testing
test/next_value_flat_map.rbcoversnext [..]in flat_map over int and string element arrays, plus a plain (no-next) flat_map to pin the unchanged path. Expected regenerated fromruby. Verified under ASAN+UBSAN withSPINEL_GC_STRESS=1, matchingruby.