Commit 39b41092

39b41092a4f7Merged

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

Description

Empty array literal assigned to a typed array ivar

@x = [] where @x is a poly/int/str/float array slot now emits the matching sp_*Array_new() constructor instead of the default sp_IntArray_new(), fixing the -Werror pointer-type mismatch (the local assignment path already did this).

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

Details

Commit
39b41092a4f7
Parent
6587a1ae7a8f

src/codegen.cmodifiedView file

@@ -4459,11 +4459,15 @@
44594459 int sc = comp_scope_of(c, id)->class_id;
44604460 TyKind ivt = TY_INT;
44614461 if (sc >= 0) { int iv = comp_ivar_index(&c->classes[sc], nm); if (iv >= 0) ivt = c->classes[sc].ivar_types[iv]; }
4462+ int ven = 0;
4463+ int v_empty_array = vty && !strcmp(vty, "ArrayNode") && (nt_arr(nt, v, "elements", &ven), ven == 0);
44624464 if (vty && !strcmp(vty, "NilNode")) {
44634465 if (ivt == TY_RANGE) buf_puts(b, "(sp_Range){0}");
44644466 else if (ivt == TY_POLY) buf_puts(b, "sp_box_nil()");
44654467 else buf_puts(b, default_value(ivt));
44664468 }
4469+ else if (v_empty_array && ivt == TY_POLY_ARRAY) buf_puts(b, "sp_PolyArray_new()");
4470+ else if (v_empty_array && array_kind(ivt)) buf_printf(b, "sp_%sArray_new()", array_kind(ivt));
44674471 else if (ivt == TY_POLY && comp_ntype(c, v) != TY_POLY) {
44684472 /* a poly ivar slot needs a boxed RHS */
44694473 emit_boxed(c, v, b);