Commit b726681b
b726681b7180Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified
Description
Collect a poly-scalar map block into a PolyArray (object-array receiver)
arr.map { |o| o.poly_field } over an array of objects, where the block
returns a polymorphic field (sp_RbVal), built a sp_PtrArray accumulator
and pushed the element through (void *)(sp_RbVal) — a hard C error —
while the analyzer typed the result poly_array, so the result var was a
mismatched sp_PolyArray *.
Add a poly arm to the ptr_array-receiver map: when the block returns a
poly scalar, accumulate into a sp_PolyArray and push the sp_RbVal
directly (no cast, no re-box). Surfaced in roundhouse's real-blog
results.map { |a| a.id } where Article#id widens to poly.
Closes #1076
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- b726681b7180
- Parent
- 1c1f48a59e16
spinel_codegen.rbmodifiedView file
@needs_bigint = 1 emit(" sp_PolyArray *" + tmp_arr + " = sp_PolyArray_new();") p_container = "poly_array" elsif block_ret_p == "poly" # Block returns a poly scalar (sp_RbVal), e.g. `arr.map { |o| # o.poly_field }`. analyze types the result poly_array, so the # accumulator must be a PolyArray; a PtrArray would push the # sp_RbVal through `(void *)` -- a hard C error. Issue #1076. @needs_rb_value = 1 emit(" sp_PolyArray *" + tmp_arr + " = sp_PolyArray_new();") p_container = "poly_array" else # obj/ptr/poly block return: keep a PtrArray of the result. # obj/ptr block return: keep a PtrArray of the result. emit(" sp_PtrArray *" + tmp_arr + " = sp_PtrArray_new();") p_container = "ptr_array" end elsif block_ret_p == "bigint" @needs_bigint = 1 emit(" sp_PolyArray_push(" + tmp_arr + ", sp_box_int(sp_bigint_to_int((sp_Bigint *)" + lastv_p + ")));") elsif block_ret_p == "poly" # lastv_p is already an sp_RbVal; push it straight into the # PolyArray (no (void *) cast, no re-box). Issue #1076. emit(" sp_PolyArray_push(" + tmp_arr + ", " + lastv_p + ");") else emit(" sp_PtrArray_push(" + tmp_arr + ", (void *)(" + lastv_p + "));") endtest/map_obj_array_poly_field.rbaddedView file
Loading diff…