Commit d10a84c4
d10a84c4718cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: box a scalar splat element into a poly-widened param under promote
emit_args_filled spreads a splatted array's elements positionally via emit_array_elem_at, which yields the raw element (int for an IntArray). When the receiving param is widened to poly under promote, box the scalar element to match. Gated on a poly param, so default mode (and optcarrot, which never widens) is unaffected. Unblocks splat_call.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- d10a84c4718c
- Parent
- 2e0f15a6e310
src/codegen_fold.cmodifiedView file
@@ -3204,7 +3204,15 @@
32043204
}32053205
else if (splat_tmp >= 0 && i >= splat_idx) {32063206
/* this param comes from the splatted array at offset (i - splat_idx) */3207-
emit_array_elem_at(splat_at, splat_tmp, i - splat_idx, out);3207+
LocalVar *sp = m ? scope_local(m, m->pnames[i]) : NULL;3208+
TyKind set = ty_array_elem(splat_at);3209+
if (sp && sp->type == TY_POLY && set != TY_POLY && set != TY_UNKNOWN) {3210+
/* a scalar splat element into a poly-widened param: box it */3211+
Buf eb; memset(&eb, 0, sizeof eb);3212+
emit_array_elem_at(splat_at, splat_tmp, i - splat_idx, &eb);3213+
emit_boxed_text(c, set, eb.p ? eb.p : "0", out); free(eb.p);3214+
}3215+
else emit_array_elem_at(splat_at, splat_tmp, i - splat_idx, out);32083216
}32093217
else {32103218
/* Check if this param has a keyword match (lookup by param name in kwh). */