Commit 2b02f7b1
2b02f7b1a841Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): #313 unbox poly-typed value to const char * at String#<< call site
When a module method returns @hash[k] || "" over a heterogeneously-
valued hash, the inferred return type is sp_RbVal (poly) per #303's
write-side fix. Passing that value directly into String#<< (which
lowers to sp_String_append, signature const char * for the
appended payload) emitted a raw sp_RbVal argument and the C
compiler rejected the type mismatch.
Both << codegen sites (expression context returning the buffer,
statement context discarding the result) now detect a poly arg and
wrap it in sp_poly_to_s — the universal poly→string coercion that
already handles every tag (string passes through, ints stringify,
sym/nil/bool fall through).
Sister fix to #303: that one made the hash poly-typed when written heterogeneously; this is the read path flowing into a narrow callee. Same family as #207 / #286 / #287 / #304 (widening must propagate across whatever lowering the value lands at).
Fixes #313
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 2b02f7b1a841
- Parent
- ef05cb1aa590
spinel_codegen.rbmodifiedView file
if lt == "mutable_str" @needs_mutable_str = 1 rc = compile_expr_gc_rooted(recv) # Issue #313: unbox a poly-typed arg to const char * before # sp_String_append (which takes const char *). sp_poly_to_s # handles every tag — string passes through, others coerce. args_id = @nd_arguments[nid] if args_id >= 0 arg_ids = get_args(args_id) if arg_ids.length > 0 && infer_type(arg_ids[0]) == "poly" val = "sp_poly_to_s(" + compile_expr(arg_ids[0]) + ")" return "(sp_String_append(" + rc + ", " + val + "), " + rc + ")" end end val = compile_arg0(nid) return "(sp_String_append(" + rc + ", " + val + "), " + rc + ")" end if at == "mutable_str" emit(" sp_String_append(" + rc + ", " + val + "->data);") else emit(" sp_String_append(" + rc + ", " + val + ");") if at == "poly" # Issue #313: a poly-typed source (e.g. a module # method returning sp_RbVal from a SymPolyHash # read) needs runtime unbox to const char * before # sp_String_append. sp_poly_to_s handles every tag. emit(" sp_String_append(" + rc + ", sp_poly_to_s(" + val + "));") else emit(" sp_String_append(" + rc + ", " + val + ");") end end end endtest/poly_str_append.rbaddedView file
Loading diff…
test/poly_str_append.rb.expectedaddedView file
Loading diff…