Commit 2273c1ed
2273c1ed0e30Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(analyze,codegen): Array.new(n, nil) returns poly_array of nils
Array.new(3, nil) in MRI fills each slot with the nil
singleton and .inspect prints "[nil, nil, nil]". Spinel
previously lowered the call to a sp_IntArray pushing the
C default 0, and inspect printed "[0, 0, 0]" -- the fill
value's nil type never picked up a dedicated arm in either
the analyzer's Array.new dispatch or the codegen's compile_
constructor_expr.
Add a "nil" arm in both, parallel to the "poly" arm. The
result is sp_PolyArray filled with sp_box_nil(), so downstream
[i].nil? / inspect / etc. see the real nil tag.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 2273c1ed0e30
- Parent
- 712d6114c584
spinel_analyze.rbmodifiedView file
@needs_rb_value = 1 return "poly_array" end # `Array.new(n, nil)` fills each slot with the nil singleton; # the element shape is sp_RbVal with the nil tag, so the # result must be poly_array (not int_array filled with 0). # Mirrors the codegen arm in compile_constructor_expr. if vt == "nil" @needs_rb_value = 1 @needs_gc = 1 return "poly_array" end if type_is_pointer(vt) == 1 @needs_gc = 1 return vt + "_ptr_array"spinel_codegen.rbmodifiedView file
Loading diff…
test/array_new_nil_fill.rbaddedView file
Loading diff…
test/array_new_nil_fill.rb.expectedaddedView file
Loading diff…