Commit d2f690be

d2f690be29e5Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 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

@@ -5523,10 +5523,23 @@
55235523 if bbs.length > 0
55245524 recv_t = infer_type(recv)
55255525 bp1 = get_block_param(nid, 0)
5526+ bp2_map = get_block_param(nid, 1)
55265527 push_scope
55275528 if bp1 != ""
55285529 declare_var(bp1, iter_elem_type(recv_t))
55295530 end
5531+ # Hash#map { |k, v| ... } — value param `v` needs its hash-value
5532+ # type, not the iter elem type (which for sym_int_hash is "symbol").
5533+ # Without this, infer_type on the body sees `v` as int (default)
5534+ # and the result array variant comes out wrong (e.g. str values
5535+ # get pushed into IntArray). hash_value_part uses short names
5536+ # ("str", "int", "poly"); translate "str" → "string" since
5537+ # declare_var expects the long form.
5538+ if bp2_map != "" && is_hash_type(recv_t) == 1
5539+ vt_map = hash_value_part(recv_t)
5540+ vt_map = "string" if vt_map == "str"
5541+ declare_var(bp2_map, vt_map)
5542+ end
55305543 bret = infer_type(bbs.last)
55315544 pop_scope
55325545 # `recv.map { _1[:k] }` on a poly_array: the block body is