Commit d80c0225
d80c0225978eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(analyze,codegen): map block returning String.new -> mutable_str_ptr_array
Sibling to #519. The literal-array path [String.new] was fixed
in #519 to infer as mutable_str_ptr_array (a sp_PtrArray of
sp_String*). The .map { String.new } path used a separate
inference cascade -- the map-result type-switch in both
spinel_analyze.rb and spinel_codegen.rb's int_array recv branch
didn't recognize mutable_str as a block-return witness, so the
accumulator stayed at the int_array default and codegen emitted
sp_IntArray_push(arr, sp_String_new("")) -- the same int-from-
pointer C error.
Add a mutable_str arm in:
- spinel_analyze.rb infer_call_type's map branch: returns
mutable_str_ptr_arraywhen the block tail infers as mutable_str. - spinel_codegen.rb compile_map_expr's int_array/sym_array recv
branch: accumulator becomes sp_PtrArray with
(void *)valpush, matching the array-literal arm's emit shape.
Other map recv branches (range, str_array, poly_array, ptr_array) have the same fall-through but aren't the issue's reproduction shape. They land in a follow-up if real-world cases trip them.
Closes #522
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- d80c0225978e
- Parent
- 9933a13de93b
spinel_analyze.rbmodifiedView file
if is_obj_type(bret) == 1 return bret + "_ptr_array" end # Block returns `String.new` / a local widened to mutable_str # via `s = ""; s << ...`: result is an array of sp_String*. # Sibling to #519's array-literal arm; #522 noted the gap. if bret == "mutable_str" @needs_gc = 1 return "mutable_str_ptr_array" end # Block returns a 1D array (e.g. # `[1, 6].map { (0..n).map { i } }` or # `(0..3).map { |i| (0..3).map { ... } }`) — eachspinel_codegen.rbmodifiedView file
Loading diff…
test/map_block_string_new.rbaddedView file
Loading diff…
test/map_block_string_new.rb.expectedaddedView file
Loading diff…