Commit d903820a

d903820a0c43Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): sym_X_hash -> sym_poly_hash conversion at call boundary

After the #676 kwargs-bind path and #685 hash-variant cross-merge fixes, a Symbol-keyed Hash literal flowing into a sym_poly_hash- typed callee param fell through with a raw sp_SymStrHash * cast. The receiving callee read sp_RbVal values from what was actually a const char * layout; reads returned garbage and complex flows segfaulted.

Extend hash_variant_convert with dst_t == "sym_poly_hash" arms:

  • sym_int_hash -> sp_SymIntHash_to_sym_poly (helper already exists)
  • sym_str_hash -> sp_SymStrHash_to_sym_poly (ditto)

compile_expr_for_expected_type's hash-to-hash arm already routes through hash_variant_convert; the missing piece was the destination direction, not the entry point.

Tests: default 461/0/0, promote 461/0/0, optcarrot checksum 59662. New regression in test/hash_variant_call_boundary_sym.rb covers the literal -> sym_poly_hash and the merge-then-pass shapes.

Closes #690

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
d903820a0c43
Parent
a9c8fa520acc

spinel_codegen.rbmodifiedView file

@@ -1889,6 +1889,20 @@
18891889 return "sp_StrPolyHash_from_sym_poly_hash(" + src_var + ")"
18901890 end
18911891 end
1892+ if dst_t == "sym_poly_hash"
1893+ if src_t == "sym_int_hash"
1894+ @needs_sym_poly_hash = 1
1895+ @needs_sym_int_hash = 1
1896+ @needs_rb_value = 1
1897+ return "sp_SymIntHash_to_sym_poly(" + src_var + ")"
1898+ end
1899+ if src_t == "sym_str_hash"
1900+ @needs_sym_poly_hash = 1
1901+ @needs_sym_str_hash = 1
1902+ @needs_rb_value = 1
1903+ return "sp_SymStrHash_to_sym_poly(" + src_var + ")"
1904+ end
1905+ end
18921906 ""
18931907 end
18941908