Commit cc1ae79a
cc1ae79a0c0dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Fix poly_arr_set_hash not growing PolyArray and wrong default for empty [] boxing
sp_poly_arr_set_hash with a PolyArray receiver silently dropped writes when idx >= len, corrupting the ||= pattern used in nested hash/array structures (e.g. @h[bank][idx][0] ||= []).
Two fixes:
- sp_poly_arr_set_hash: grow PolyArray with nil-padding when idx >= len, matching the behavior of sp_IntArray_set for IntArray receivers.
- emit_boxed in codegen: box TY_UNKNOWN empty [] as PolyArray instead of IntArray. The poly context (||= in a poly slot) needs a container that can hold any element type via sp_poly_shl; IntArray would silently convert boxed elements via sp_poly_to_i(obj)=0.
Fixes bundle_classd_11 (multi-write from poly receiver) and bundle_class_06 (push_int container initialization).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- cc1ae79a0c0d
- Parent
- d68aba184eb4
lib/sp_runtime.hmodifiedView file
@@ -3832,7 +3832,14 @@
38323832
val.tag == SP_TAG_FLT ? val.v.f : (mrb_float)val.v.i); break;38333833
case SP_BUILTIN_STR_ARRAY: sp_StrArray_set((sp_StrArray*)v.v.p, idx,38343834
val.tag == SP_TAG_STR ? val.v.s : NULL); break;3835-
case SP_BUILTIN_POLY_ARRAY: sp_PolyArray_set((sp_PolyArray*)v.v.p, idx, val); break;3835+
case SP_BUILTIN_POLY_ARRAY: {3836+
sp_PolyArray *_pa = (sp_PolyArray*)v.v.p;3837+
if (_pa && !_pa->frozen) {3838+
while (_pa->len <= idx) sp_PolyArray_push(_pa, sp_box_nil());3839+
_pa->data[idx] = val;3840+
}3841+
break;3842+
}38363843
case SP_BUILTIN_POLY_POLY_HASH: sp_PolyPolyHash_set((sp_PolyPolyHash*)v.v.p, sp_box_int(idx), val); break;38373844
default: break;38383845
}src/codegen.cmodifiedView file
Loading diff…