Commit 63fb62ec
63fb62ec4328Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): support Array#flat_map block returning ptr_array
When a flat_map block returned a ptr_array, the inference fell back to the receiver type and the codegen mismatched:
/tmp/_t.c:53:24: error: initialization of 'sp_PtrArray *' from incompatible pointer type 'sp_IntArray *'
Follow-up to the introduction of ptr_array (mirrors the earlier
poly_array fix): flat_map's block-return recognition (in
infer_call_type) and accumulator typing (in compile_flat_map_expr)
were missed when the new type was added. The block-param type case
also needed extending to ptr_array_elem_type(rt) so that
|f|-style params land on the right obj type.
Adds test/array_flat_map_ptr.rb.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 63fb62ec4328
- Parent
- b75070d3abf9
spinel_codegen.rbmodifiedView file
if bbs.length > 0 bret = infer_type(bbs.last) # If block returns an array type, use it as result type if is_array_type(bret) == 1 if is_array_type(bret) == 1 || is_ptr_array_type(bret) == 1 return bret end end end end # Fall back to receiver type if block doesn't return an array if is_array_type(block_ret) == 0 if is_array_type(block_ret) == 0 && is_ptr_array_type(block_ret) == 0 block_ret = rt end @needs_gc = 1 elem_type = "float" elsif rt == "poly_array" elem_type = "poly" elsif is_ptr_array_type(rt) == 1 elem_type = ptr_array_elem_type(rt) end declare_var(bp1, elem_type) emit(" for (mrb_int " + tmp_i + " = 0; " + tmp_i + " < sp_" + pfx_src + "_length(" + rc + "); " + tmp_i + "++) {")test/array_flat_map_ptr.rbaddedView file
Loading diff…