Commit 858f8fac
858f8facc9a5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #165 from mame/pr/map-non-array-recv-returns-array
fix(codegen): infer array-returning result for non-array recv on #map
Details
- Commit
- 858f8facc9a5
- Parent
- cc56bd446ad2
- Merge parent
- 6cef5f84c373
spinel_codegen.rbmodifiedView file
@@ -2887,10 +2887,23 @@
28872887
if is_obj_type(bret) == 128882888
return bret + "_ptr_array"28892889
end2890+
# Block returns a non-trivial type (an array literal,2891+
# poly value, ...). The map's overall result is still an2892+
# Array — fall through to the recv-based default below2893+
# only when recv is already array-shaped, otherwise2894+
# return int_array as a generic placeholder.28902895
end28912896
end28922897
end2893-
return infer_type(recv)2898+
rt_recv = infer_type(recv)2899+
# Range#map / Integer#step.map / non-array recv → result is2900+
# an Array, not a Range/IntArray. Without this, an2901+
# `@x = (0...n).map {...}` recorded the ivar as `range` and2902+
# later `@x = something_else` writes failed to type-check.2903+
if rt_recv == "range" || rt_recv == "int"2904+
return "int_array"2905+
end2906+
return rt_recv28942907
end28952908
return "int_array"28962909
endtest/map_range_recv_array_block.rbaddedView file
Loading diff…