Commit 9a76fc98
9a76fc98a8ddMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): scan_ivars_multi_target_type handles collect + trusts block return
Follow-up to #242 — Gemini's two medium review concerns.
-
collectalias.collectis the standard alias formapin Ruby; the multi-write peek-through handledmaponly, soA, B = arr.collect { block }fell through to thert-based heuristics and missed the array-of-array element type. -
Trust the block return even when it's
int. The original guardbret != "int" && bret != "" && bret != "void"deferred tort(the outer call's inferred type) on int returns. But the comment block right above explains thatrtis unreliable for nested-array shapes — Spinel collapses array-of-array toint_arrayplaceholder. Trustingbretdirectly when it's non-empty / non-void is the safer rule, and for plainint_arraycases the rt-fallthrough also returned"int"anyway, so this is monotonic on the working cases and strictly better on the collapsed cases.
295 pass / build clean.
Refs #242
Co-Authored-By: Yusuke Endoh [email protected] Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 9a76fc98a8dd
- Parent
- b82298afb7ef
spinel_codegen.rbmodifiedView file
# mapped array, so its type is the block's return type. Spinel # collapses array-of-array to a placeholder (int_array) at the # outer infer_type level, so we have to peek through the call # node directly to recover the element type. if @nd_type[val_id] == "CallNode" && @nd_name[val_id] == "map" # node directly to recover the element type. `collect` is the # standard alias for `map`; treat both. Trust the block return # even when it's `int` — `rt` (the outer call's inferred type) # is unreliable for nested-array shapes per the comment above, # so the block return is more authoritative. if @nd_type[val_id] == "CallNode" && (@nd_name[val_id] == "map" || @nd_name[val_id] == "collect") blk = @nd_block[val_id] if blk >= 0 bbody = @nd_body[blk] bbs = get_stmts(bbody) if bbs.length > 0 bret = infer_type(bbs.last) if bret != "int" && bret != "" && bret != "void" if bret != "" && bret != "void" return bret end end