Commit b75070d3

b75070d3abf9Merged

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

Description

fix(codegen): support Array#each_with_object on ptr_array

each_with_object only matched the typed-array list. On a ptr_array the dispatcher fell through and the loop body was never emitted:

n = 0 [Bar.new(1), Bar.new(2)].each_with_object("") {|_e, _a| n += 1 } puts n # ruby: 2, spinel: 0

Follow-up to the introduction of ptr_array (mirrors the earlier poly_array fix): each_with_object was missed when the new type was added. elem_type_of_array already maps *_ptr_array to its obj element type via ptr_array_elem_type, so the block param is typed correctly once the receiver-type check accepts ptr_array.

Adds test/array_each_with_object_ptr.rb.

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

Details

Commit
b75070d3abf9
Parent
b6d93414ef23

spinel_codegen.rbmodifiedView file

@@ -21029,7 +21029,7 @@
2102921029 result = new_temp
2103021030 emit(" " + obj_ct + " " + result + " = " + obj_arg + ";")
2103121031 tmp_i = new_temp
21032- if is_array_type(rt) == 1
21032+ if is_array_type(rt) == 1 || is_ptr_array_type(rt) == 1
2103321033 pfx = array_c_prefix(rt)
2103421034 emit(" {")
2103521035 @indent = @indent + 1