Commit 0f605284
0f605284523bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): poly_poly_hash gains fetch + dup dispatch arms
Sam Ruby's #560. When two writers to a module-level ivar
use incompatible key types (int-defaulted param vs symbol
literal), spinel widens the storage to poly_poly_hash. The
read side previously had only [] / has_key? / length /
empty? / any? / keys / values arms; fetch / dup fell through
to the unresolved-call warning and emitted 0.
Add fetch (inlined has_key + get with the default boxed to sp_RbVal) and dup (sp_PolyPolyHash_dup, already in the runtime). Sibling of the per-variant arms #551 added for str_poly_hash and sym_poly_hash. Hash#delete on poly_poly_hash is intentionally not wired here -- the runtime needs a corresponding sp_PolyPolyHash_delete helper that handles the occ-array slot bookkeeping, and the reported ActionView shape (content_for_get) uses fetch only.
Closes #560
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 0f605284523b
- Parent
- 1a76e599863a
spinel_codegen.rbmodifiedView file
@needs_rb_value = 1 return "sp_PolyPolyHash_values(" + rc + ")" end # fetch / dup / delete -- sibling of the per-variant arms # for sym/str_poly_hash. Issue #560. fetch inlines as # has_key + get with the default boxed to sp_RbVal so the # ternary's two arms agree on type. if mname == "fetch" args_id_f = @nd_arguments[nid] if args_id_f >= 0 aargs_f = get_args(args_id_f) if aargs_f.length >= 1 key_f = box_expr_to_poly(aargs_f[0]) if aargs_f.length >= 2 defval_f = box_expr_to_poly(aargs_f[1]) return "(sp_PolyPolyHash_has_key(" + rc + ", " + key_f + ") ? sp_PolyPolyHash_get(" + rc + ", " + key_f + ") : (" + defval_f + "))" end return "sp_PolyPolyHash_get(" + rc + ", " + key_f + ")" end end end if mname == "dup" || mname == "clone" return "sp_PolyPolyHash_dup(" + rc + ")" end end if recv_type == "str_int_hash" if mname == "[]"test/poly_poly_hash_fetch_dup.rbaddedView file
Loading diff…
test/poly_poly_hash_fetch_dup.rb.expectedaddedView file
Loading diff…