Commit c655d53d

c655d53dbc21Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(analyze): empty array widens to poly_array on Hash/Array push (#440)

#412 added the int_array → _array upgrade in scan_locals's push observation for primitive element types (str_array, float_array, sym_array, obj_X_ptr_array, poly_array). Container element types — Hash literals and nested Arrays — fell through to the bottom of the if/elsif chain and stayed at int_array, then sp_IntArray_push errored with int-from-pointer conversion.

Extend the push observation: when the pushed arg's type is a hash variant (is_hash_type) or an array variant (is_array_type, which covers both flat typed arrays and *_ptr_array nested arrays), promote the local to poly_array. Spinel has no _ptr_array or _ptr_array_ptr_array slot — poly_array is the canonical container-of-containers shape, matching the literal-array inference at infer_array_elem_type_from_ids (the typed-array and hash arms at line 2400 / 2414).

Closes #440

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

Details

Commit
c655d53dbc21
Parent
c915ee1ac501

spinel_analyze.rbmodifiedView file

@@ -17713,6 +17713,23 @@
1771317713 end
1771417714 ki = ki + 1
1771517715 end
17716+ elsif is_hash_type(arg_type) == 1 || is_array_type(arg_type) == 1 || is_ptr_array_type(arg_type) == 1
17717+ # Hash or typed-array element: spinel has no
17718+ # <hash>_ptr_array / <array>_ptr_array_ptr_array slot,
17719+ # so box each push via poly_array. Mirrors the literal-
17720+ # array inference shape at infer_array_elem_type_from_ids
17721+ # (line 2400+ / 2414+).
17722+ @needs_rb_value = 1
17723+ @needs_gc = 1
17724+ ki = 0
17725+ while ki < names.length
17726+ if names[ki] == arr_name
17727+ if types[ki] == "int_array"
17728+ types[ki] = "poly_array"
17729+ end
17730+ end
17731+ ki = ki + 1
17732+ end
1771617733 end
1771717734 end
1771817735 end