Commit 44d00376

44d00376b6beMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Box the RHS of a poly ivar write

An ivar whose slot widened to poly (e.g. assigned an Integer in one method and a String in another) was written with the raw scalar RHS, failing the -Werror C compile. Concrete RHS values are now boxed (sp_box_*) into the poly slot, and a nil RHS uses sp_box_nil.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
44d00376b6be
Parent
3af1c7e7431b

src/codegen.cmodifiedView file

@@ -4172,8 +4172,13 @@
41724172 if (sc >= 0) { int iv = comp_ivar_index(&c->classes[sc], nm); if (iv >= 0) ivt = c->classes[sc].ivar_types[iv]; }
41734173 if (vty && !strcmp(vty, "NilNode")) {
41744174 if (ivt == TY_RANGE) buf_puts(b, "(sp_Range){0}");
4175+ else if (ivt == TY_POLY) buf_puts(b, "sp_box_nil()");
41754176 else buf_puts(b, default_value(ivt));
41764177 }
4178+ else if (ivt == TY_POLY && comp_ntype(c, v) != TY_POLY) {
4179+ /* a poly ivar slot needs a boxed RHS */
4180+ emit_boxed(c, v, b);
4181+ }
41774182 else {
41784183 emit_expr(c, v, b);
41794184 }