Commit 87fd5065
87fd506580c2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(analyze): force_encoding/encode/b on mutable_str returns string (#446)
#441's fix gated the force_encoding / encode / b return-type inference on `recv == "string"`, leaving the sp_String * (mutable_str) receiver case unfixed. Codegen for a mutable_str receiver dispatches the inner call against `rc + "->data"` (line 12010), so force_encoding's body returns `lv_out->data` — a const char *. The function signature still defaulted to mrb_int and tripped the C compile with int-from-pointer.
Add the mutable_str arm: return "string" too, matching the body's `->data` value type so the C signature reads `const char *` and the return expression fits.
Closes #446
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 87fd506580c2
- Parent
- 40b88f06a99e
spinel_analyze.rbmodifiedView file
# the shortest collision target; struct field accessors etc. # commonly take that single-letter shape). if mname == "force_encoding" || mname == "encode" || mname == "b" if recv >= 0 && infer_type(recv) == "string" return "string" if recv >= 0 rt_fe = infer_type(recv) if rt_fe == "string" return "string" end # A mutable_str (sp_String *) recv goes through codegen's # mutable-str arm which dispatches the inner call against # `rc + "->data"`; force_encoding's body return is then the # mutable's `->data` (const char *), not the wrapping struct # pointer. The function-return signature should match — pick # "string", not "mutable_str", so the C signature reads # `const char *` and the body's `return lv_out->data` fits. if rt_fe == "mutable_str" return "string" end end end if mname == "include?"test/mutable_str_force_encoding_return.rbaddedView file
Loading diff…
test/mutable_str_force_encoding_return.rb.expectedaddedView file
Loading diff…