Commit 1bbd268b
1bbd268b3780Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): compile_expr_as_string unboxes poly value via .v.s
Issue #651: an ivar inferred as poly (sp_RbVal) because a kwarg: nil-defaulted param writes it, then read at a typed-string-hash
setter site (bag.h["k2"] = c.loc where bag.h is str_str_hash),
flowed the boxed value into sp_StrStrHash_set(_, _, sp_RbVal).
The C signature wants const char * -> compile error.
compile_expr_as_string already coerces symbol -> sp_sym_to_s
for the symbol-arm case; extend with a poly -> .v.s arm so the
canonical "poly value carrying a string payload" shape also
type-checks at the typed-hash setter boundary. Mirrors the
existing is_a?(String)-narrowed unbox.
Test pins the minimal reporter shape (kwarg-nil-default + typed
str_str_hash setter). Surfaced in tep's
action_controller/base.rb's @location = location chain feeding
the Tep::Server response headers.
Closes #651.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 1bbd268b3780
- Parent
- 9d60619944ab
spinel_codegen.rbmodifiedView file
# that still expect const char * (catch/throw tag, hash key, etc.). def compile_expr_as_string(nid) s = compile_expr(nid) if infer_type(nid) == "symbol" t = infer_type(nid) if t == "symbol" return "sp_sym_to_s(" + s + ")" end # Issue #651: a poly-typed value (commonly an ivar inferred as # poly because a `kwarg: nil`-defaulted param writes it) flowing # into a setter that expects `const char *` (sp_StrStrHash_set, # sp_SymStrHash_set, ...) needs the unboxed string payload. The # is_a?(String)-narrowed read site already does this; extend to # the un-narrowed shape so the typed-hash setter type-checks. if t == "poly" @needs_rb_value = 1 return "(" + s + ").v.s" end s endtest/poly_value_into_str_str_hash.rbaddedView file
Loading diff…
test/poly_value_into_str_str_hash.rb.expectedaddedView file
Loading diff…