Commit dcafcbb1

dcafcbb1d9f2Merged

Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

fix(codegen): support Array#+ on ptr_array

a + b on two ptr_arrays fell through to the default + codegen and the result temp stayed 0:

a = [Bar.new(1)]; b = [Bar.new(2)] puts (a + b).length # ruby: 2, spinel: 0

Follow-up to the introduction of ptr_array (mirrors the earlier poly_array fix): the dispatcher's type list and the result-type inference both need to accept *_ptr_array. sp_PtrArray_dup landed with the previous shuffle commit.

Adds test/array_plus_ptr.rb.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
dcafcbb1d9f2
Parent
87090924f784

spinel_codegen.rbmodifiedView file

@@ -1676,7 +1676,7 @@
16761676 if lt == "poly"
16771677 return "poly"
16781678 end
1679- if is_array_type(lt) == 1
1679+ if is_array_type(lt) == 1 || is_ptr_array_type(lt) == 1
16801680 return lt
16811681 end
16821682 if lt == "float"
@@ -13873,7 +13873,7 @@
1387313873 @needs_string_helpers = 1
1387413874 return "sp_poly_add(" + compile_expr(recv) + ", " + box_expr_to_poly(@nd_arguments[nid] >= 0 ? get_args(@nd_arguments[nid])[0] : -1) + ")"
1387513875 end
13876- if is_array_type(lt) == 1
13876+ if is_array_type(lt) == 1 || is_ptr_array_type(lt) == 1
1387713877 rc = compile_expr_gc_rooted(recv)
1387813878 arg = compile_arg0(nid)
1387913879 pfx = array_c_prefix(lt)