Commit d2f690be
d2f690be29e5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
analyze,codegen: Hash block methods (map / transform_values) on str-keyed and str-valued variants
Add map + transform_values arms for str_int_hash, sym_str_hash, and str_str_hash. sym_int_hash had map already; the str-keyed and str-valued variants fell through to the unresolved-call path and emitted `(mrb_int)0` into the typed-hash pointer slot.
analyze's hash map arm needed a tweak too: it only declared the key block param, so infer_type on the body saw `v` as int and the result array variant came out wrong (str values pushed into IntArray). Declare bp2 with hash_value_part(recv_t) — translating the short "str" name to "string" since declare_var expects the long form.
Fixes #851
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- d2f690be29e5
- Parent
- 14c43aee0945
spinel_analyze.rbmodifiedView file
if bbs.length > 0 recv_t = infer_type(recv) bp1 = get_block_param(nid, 0) bp2_map = get_block_param(nid, 1) push_scope if bp1 != "" declare_var(bp1, iter_elem_type(recv_t)) end # Hash#map { |k, v| ... } — value param `v` needs its hash-value # type, not the iter elem type (which for sym_int_hash is "symbol"). # Without this, infer_type on the body sees `v` as int (default) # and the result array variant comes out wrong (e.g. str values # get pushed into IntArray). hash_value_part uses short names # ("str", "int", "poly"); translate "str" → "string" since # declare_var expects the long form. if bp2_map != "" && is_hash_type(recv_t) == 1 vt_map = hash_value_part(recv_t) vt_map = "string" if vt_map == "str" declare_var(bp2_map, vt_map) end bret = infer_type(bbs.last) pop_scope # `recv.map { _1[:k] }` on a poly_array: the block body isspinel_codegen.rbmodifiedView file
Loading diff…
test/hash_block_methods_variants.rbaddedView file
Loading diff…
test/hash_block_methods_variants.rb.expectedaddedView file
Loading diff…