Commit 48c65a40
48c65a4089f0Merged
taakuuyaa <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): symbol-idx arm for chained []= / []op= on poly-recv sym hashes
When a Hash literal is boxed into a poly_array and later mutated via the
array (arr[i][:k] = v or arr[i][:k] += v), the indexed assignment
silently no-op'd because the poly-recv dispatch lacked a symbol-idx arm.
The string-idx arm — already present and added by #456 (chained_aset_on_poly_hash_recv) — is mirrored here for the SymIntHash / SymPolyHash variants. Additionally, compile_index_op_assign gains a poly-recv + symbol-idx arm dispatching to SymIntHash; SymPolyHash compound-assign needs poly-op semantics and is deferred.
Add test/array_of_hash_aset_sym.rb covering:
- arr[i][:k] = v (direct assignment)
- arr[i][:k] += v (compound assignment)
- arr.each { |f| f[:k] += v } (block param widened to poly)
- arr.each_with_index { |f, i| f[:k] = v }
Co-Authored-By: Claude [email protected]
Details
- Commit
- 48c65a4089f0
- Parent
- c3adf401f22e
spinel_codegen.rbmodifiedView file
emit(" else if (" + cur_h + ".cls_id == SP_BUILTIN_STR_POLY_HASH) sp_StrPolyHash_set((sp_StrPolyHash *)" + cur_h + ".v.p, " + idx + ", " + vbox_tmp + ");") return end # Symbol index + poly recv: mirror of the string-idx arm above # for Sym*Hash variants. Surfaces in `arr[i][:k] = v` where the # outer container is a poly_array of boxed sym_int_hash / # sym_poly_hash. Without this arm the assignment silently no-ops # (falls through to Array arms that never match). if idx_t_poly == "symbol" @needs_rb_value = 1 vbox = val if val_t_poly != "poly" vbox = box_value_to_poly(val_t_poly, val) end vbox_tmp = new_temp emit(" sp_RbVal " + vbox_tmp + " = " + vbox + ";") cur_h = new_temp emit(" sp_RbVal " + cur_h + " = " + rc + ";") emit(" if (" + cur_h + ".cls_id == SP_BUILTIN_SYM_INT_HASH) sp_SymIntHash_set((sp_SymIntHash *)" + cur_h + ".v.p, (sp_sym)(" + idx + "), " + vbox_tmp + ".v.i);") emit(" else if (" + cur_h + ".cls_id == SP_BUILTIN_SYM_POLY_HASH) sp_SymPolyHash_set((sp_SymPolyHash *)" + cur_h + ".v.p, (sp_sym)(" + idx + "), " + vbox_tmp + ");") return end # Poly index (sp_RbVal): the key's concrete type isn't known # statically, so the dispatch must read the key's tag at # runtime. Surfaces in `merged[k] = v` inside an `each` ", sp_SymIntHash_get(" + tt + ", " + ti + ") " + op + " (" + val + ")); }") return end # Poly recv + symbol idx: surfaces in `arr[i][:k] += v` (and the # each-block analog `f[:k] += v` where f is destructured from a # poly_array of boxed hashes — block param type is widened to # poly). Mirrors the `[]=` arm in compile_bracket_assign. Only # SymIntHash is dispatched here; SymPolyHash compound-assign needs # poly-op semantics and is deferred. if rt == "poly" idx_t = infer_type(arg_ids[0]) if idx_t == "symbol" @needs_rb_value = 1 cur_h = new_temp k_t = new_temp v_t = new_temp h_t = new_temp emit(" {") emit(" sp_RbVal " + cur_h + " = " + rc + ";") emit(" sp_sym " + k_t + " = (sp_sym)(" + idx + ");") emit(" mrb_int " + v_t + " = (" + val + ");") emit(" if (" + cur_h + ".cls_id == SP_BUILTIN_SYM_INT_HASH) {") emit(" sp_SymIntHash *" + h_t + " = (sp_SymIntHash *)" + cur_h + ".v.p;") emit(" sp_SymIntHash_set(" + h_t + ", " + k_t + ", sp_SymIntHash_get(" + h_t + ", " + k_t + ") " + op + " " + v_t + ");") emit(" }") emit(" }") return end end end # `obj.attr <op>= val` family helper -- builds thetest/array_of_hash_aset_sym.rbaddedView file
Loading diff…
test/array_of_hash_aset_sym.rb.expectedaddedView file
Loading diff…