Commit c6fec56e
c6fec56e9af7Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): N.times.map { array } collects into sp_PtrArray
T.Yamada's #553: 2.times.map { gets.split.map &:to_i }
failed at C compile with -Wint-conversion (sp_IntArray
pointers handed to sp_IntArray_push's mrb_int second arg).
compile_map_expr's times.map special path always built
sp_IntArray for the outer accumulator regardless of the
block's return type; only string and float were typed
correctly.
When the block returns any array shape (int_array,
str_array, float_array, sym_array, poly_array, or any
*_ptr_array nesting), build sp_PtrArray instead. Analyze
already infers <inner>_ptr_array as the static type for
this shape (sibling to the regular recv.map { array } arm
that's been in place since #519), and the inspect helpers
(sp_IntArrayPtrArray_inspect etc.) format the result
correctly. The "cannot resolve call to 'times'" warning at
the top of analyze's stderr is unrelated and pre-existing;
codegen handled the times.map pattern via this special path
all along.
Closes #553
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- c6fec56e9af7
- Parent
- f25fe0d072a4
spinel_codegen.rbmodifiedView file
end tmp_arrn = new_temp tmp_in = new_temp # When the block body returns an array (or any pointer-shaped # value), the outer .map collects them into a sp_PtrArray # rather than sp_IntArray (which would pun the IntArray # pointers as mrb_int and trip -Wint-conversion). Issue #553: # `2.times.map { gets.split.map &:to_i }` builds an # array-of-IntArrays; static type is int_array_ptr_array # and inspect knows how to render it. nested_arr_outer = 0 if res_type == "string" @needs_str_array = 1 emit(" sp_StrArray *" + tmp_arrn + " = sp_StrArray_new();") elsif res_type == "float" emit(" sp_FloatArray *" + tmp_arrn + " = sp_FloatArray_new();") elsif res_type == "int_array" || res_type == "str_array" || res_type == "float_array" || res_type == "sym_array" || res_type == "poly_array" || res_type.end_with?("_ptr_array") @needs_gc = 1 nested_arr_outer = 1 emit(" sp_PtrArray *" + tmp_arrn + " = sp_PtrArray_new();") else @needs_int_array = 1 emit(" sp_IntArray *" + tmp_arrn + " = sp_IntArray_new();") emit(" sp_StrArray_push(" + tmp_arrn + ", " + lastv + ");") elsif res_type == "float" emit(" sp_FloatArray_push(" + tmp_arrn + ", " + lastv + ");") elsif nested_arr_outer == 1 emit(" sp_PtrArray_push(" + tmp_arrn + ", " + lastv + ");") else emit(" sp_IntArray_push(" + tmp_arrn + ", " + lastv + ");") endtest/times_map_nested_array.rbaddedView file
Loading diff…
test/times_map_nested_array.rb.expectedaddedView file
Loading diff…