Commit 39e260af
39e260af01b3Merged
Ryan Seys <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
analyze,codegen: Hash#delete returns the deleted value
h.delete(k) previously emitted (sp_<Variant>_delete(h, k), 0)
(or sp_box_nil() for poly variants), dropping the value and
always returning 0 / nil. CRuby returns the value that was
mapped to k (or nil / block result when the key was absent).
Rewrite the per-variant delete arms as a GCC compound expression that:
- pre-evaluates the key once into a temp,
- looks up via has_key + get (default 0 / NULL / sp_box_nil when absent, matching each variant's missing-default),
- runs the delete (no return-value change to the runtime helper),
- yields the captured value.
Sym_int / sym_str / sym_poly variants covered here. Block-form
delete (h.delete(k) { default }) and str-keyed / int-keyed
variants left for follow-up — they share the compile_body_into
plumbing already added for fetch's block form.
Analyzer side: extend the mname == "delete" return-type arm
(previously string-only) to cover the 6 sym-keyed and str-keyed
hash variants so downstream consumers see the right slot type.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 39e260af01b3
- Parent
- 24ec1cf637a4
spinel_analyze.rbmodifiedView file
if rt == "string" return "string" end if rt == "sym_int_hash" || rt == "str_int_hash" return "int" end if rt == "sym_str_hash" || rt == "str_str_hash" || rt == "int_str_hash" return "string" end if rt == "sym_poly_hash" || rt == "str_poly_hash" || rt == "poly_poly_hash" return "poly" end end end if mname == "squeeze"spinel_codegen.rbmodifiedView file
Loading diff…
test/hash_delete_returns_value.rbaddedView file
Loading diff…
test/hash_delete_returns_value.rb.expectedaddedView file
Loading diff…