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

@@ -7875,9 +7875,20 @@
78757875 # that still expect const char * (catch/throw tag, hash key, etc.).
78767876 def compile_expr_as_string(nid)
78777877 s = compile_expr(nid)
7878- if infer_type(nid) == "symbol"
7878+ t = infer_type(nid)
7879+ if t == "symbol"
78797880 return "sp_sym_to_s(" + s + ")"
78807881 end
7882+ # Issue #651: a poly-typed value (commonly an ivar inferred as
7883+ # poly because a `kwarg: nil`-defaulted param writes it) flowing
7884+ # into a setter that expects `const char *` (sp_StrStrHash_set,
7885+ # sp_SymStrHash_set, ...) needs the unboxed string payload. The
7886+ # is_a?(String)-narrowed read site already does this; extend to
7887+ # the un-narrowed shape so the typed-hash setter type-checks.
7888+ if t == "poly"
7889+ @needs_rb_value = 1
7890+ return "(" + s + ").v.s"
7891+ end
78817892 s
78827893 end
78837894