Commit 2951d3d7
2951d3d713b2Merged
Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): support Array#flat_map block returning poly_array
When a flat_map block returned a heterogeneous array, the inference side fell back to the receiver type and the codegen side mismatched:
/tmp/_t.c:28:26: error: initialization of 'sp_IntArray *' from incompatible pointer type 'sp_PolyArray *'
Follow-up to the introduction of poly_array: 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.
Adds test/array_flat_map_poly.rb.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 2951d3d713b2
- Parent
- 33db7a5aa8d7
spinel_codegen.rbmodifiedView file
@@ -2380,7 +2380,7 @@
23802380
if bbs.length > 023812381
bret = infer_type(bbs.last)23822382
# If block returns an array type, use it as result type2383-
if bret == "int_array" || bret == "str_array" || bret == "float_array" || bret == "sym_array"2383+
if bret == "int_array" || bret == "str_array" || bret == "float_array" || bret == "sym_array" || bret == "poly_array"23842384
return bret23852385
end23862386
end@@ -21726,7 +21726,7 @@
2172621726
end2172721727
end2172821728
# Fall back to receiver type if block doesn't return an array21729-
if block_ret != "int_array" && block_ret != "str_array" && block_ret != "float_array" && block_ret != "sym_array"21729+
if block_ret != "int_array" && block_ret != "str_array" && block_ret != "float_array" && block_ret != "sym_array" && block_ret != "poly_array"2173021730
block_ret = rt2173121731
end2173221732
@needs_gc = 1@@ -21743,6 +21743,8 @@
2174321743
elem_type = "string"2174421744
elsif rt == "float_array"2174521745
elem_type = "float"21746+
elsif rt == "poly_array"21747+
elem_type = "poly"2174621748
end2174721749
declare_var(bp1, elem_type)2174821750
emit(" for (mrb_int " + tmp_i + " = 0; " + tmp_i + " < sp_" + pfx_src + "_length(" + rc + "); " + tmp_i + "++) {")test/array_flat_map_poly.rbaddedView file
Loading diff…