Commit aa800fe3
aa800fe35c0bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): str_str_hash / str_int_hash bracket-assign no longer elides
Root cause for #610: compile_bracket_assign had emit arms for
sym_int_hash, sym_str_hash, sym_poly_hash, str_poly_hash,
poly_poly_hash, int_str_hash, and every array variant, but the
str_str_hash and str_int_hash arms were missing. Plus the nullable
suffix wasn't stripped at entry. So
<str_str_hash?>[k] = v reached this function, matched no rt
branch, and returned with no emit at all — silent elision of the
assignment. The whole-block body of a .each { merged[k.to_s] = ... } over a path-params dup vanished.
Fixes:
-
Strip the nullable
?at the top via base_type so astr_str_hash?(the canonical shape returned by an attr reader on an instance variable initialized nil) dispatches through the same emit asstr_str_hash. -
Add the two missing arms: str_int_hash routes the value through compile_expr_as_int and str_str_hash through compile_expr_as_string. The expr-as helpers handle the poly / sym / int RHS shapes that flow into a hash key write, so a
merged[k.to_s] = vwhere v is sp_RbVal unboxes via sp_poly_to_s rather than silently dropping.
Test: test/str_str_hash_nullable_bracket_assign.rb exercises the nullable shape end-to-end. Pre-fix the .h["c"] = "3" assignments disappeared and the hash still held only the two seeded entries; post-fix all four reads come back with the expected values.
The roundhouse comments_controller_test body (the
dispatch_request merge loop) no longer elides its body. A separate
follow-on type error in stringify_keys(sp_RbVal) surfaces now
that the surrounding code is emitted; that's an orthogonal issue
on the analyzer's Hash-vs-leaf union and isn't part of this fix.
Refs #610. 586 tests pass / bootstrap fixpoint clean.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- aa800fe35c0b
- Parent
- b0d961748de7
spinel_codegen.rbmodifiedView file
def compile_bracket_assign(nid) recv = @nd_receiver[nid] rt = infer_type(recv) # Nullable hash receivers (`str_str_hash?` etc.) should dispatch # identically to the base hash; NULL-check semantics live at the # caller, mirroring compile_call_expr's strip-? handling. Without # this, `<str_str_hash?>[k] = v` fell through every arm and # emitted nothing — the silent-elision shape reported in #610. if is_nullable_pointer_type(rt) == 1 && is_nullable_type(rt) == 1 rt = base_type(rt) end rc = compile_expr_gc_rooted(recv) args_id = @nd_arguments[nid] arg_ids = [] emit(" sp_IntStrHash_set(" + rc + ", " + idx + ", " + val + ");") return end # str_int_hash / str_str_hash were both missing here previously, # so `<str_str_hash>[k] = v` fell through compile_bracket_assign # with no emit at all — the silent-elision shape reported in #610 # where a typed-hash write inside a `.each` block disappeared. # The value side coerces through compile_expr_as_int / # compile_expr_as_string so a poly-typed RHS (the canonical # `v.is_a?(Hash) ? ... : v` ternary shape) unboxes to the cell's # stored type rather than dropping silently. if rt == "str_int_hash" val_int = compile_expr_as_int(arg_ids[1]) emit(" sp_StrIntHash_set(" + rc + ", " + idx + ", " + val_int + ");") return end if rt == "str_str_hash" val_str = compile_expr_as_string(arg_ids[1]) emit(" sp_StrStrHash_set(" + rc + ", " + idx + ", " + val_str + ");") return end if rt == "sym_int_hash" emit(" sp_SymIntHash_set(" + rc + ", " + idx + ", " + val + ");") returntest/str_str_hash_nullable_bracket_assign.rbaddedView file
Loading diff…
test/str_str_hash_nullable_bracket_assign.rb.expectedaddedView file
Loading diff…