Commit 1c1f48a5
1c1f48a59e16Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified
Description
Box the nil initializer of a poly-typed module ivar / const
A module-level @x = nil whose slot later widens to poly (sp_RbVal)
emitted a bare 0 for the nil initializer, so cst_Mod_x = 0; failed
to compile ("assigning to 'sp_RbVal' from incompatible type 'int'").
When the const slot type is poly, run the initializer through box_expr_to_poly so nil lowers to sp_box_nil() (and int/string/array seeds box to their tagged form) instead of compile_expr's raw scalar.
Closes #1075
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 1c1f48a59e16
- Parent
- d1af854201d3
spinel_codegen.rbmodifiedView file
@@ -13301,7 +13301,17 @@
1330113301
emit(" sp_init_in_progress_" + @const_names[i] + " = 1;")1330213302
end1330313303
if val == ""13304-
val = compile_expr(eid_init)13304+
# A poly (sp_RbVal) const slot needs its initializer boxed.13305+
# Otherwise a `nil` init lowers to a bare `0` and the assignment13306+
# to the sp_RbVal slot is a C type error ("assigning to 'sp_RbVal'13307+
# from incompatible type 'int'"). box_expr_to_poly handles nil13308+
# (sp_box_nil()) as well as int/string/array seeds. Issue #1075.13309+
if ct_init == "poly"13310+
@needs_rb_value = 113311+
val = box_expr_to_poly(eid_init)13312+
else13313+
val = compile_expr(eid_init)13314+
end1330513315
end1330613316
@current_lexical_scope = old_scope1330713317
emit(" cst_" + @const_names[i] + " = " + val + ";")test/module_ivar_nil_poly.rbaddedView file
Loading diff…