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_array when 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 *)val push, 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

@@ -4574,6 +4574,13 @@
45744574 if is_obj_type(bret) == 1
45754575 return bret + "_ptr_array"
45764576 end
4577+ # Block returns `String.new` / a local widened to mutable_str
4578+ # via `s = ""; s << ...`: result is an array of sp_String*.
4579+ # Sibling to #519's array-literal arm; #522 noted the gap.
4580+ if bret == "mutable_str"
4581+ @needs_gc = 1
4582+ return "mutable_str_ptr_array"
4583+ end
45774584 # Block returns a 1D array (e.g.
45784585 # `[1, 6].map { (0..n).map { i } }` or
45794586 # `(0..3).map { |i| (0..3).map { ... } }`) — each