Commit b36b0b0b
b36b0b0b79daMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: box array elements into poly targets in a nested destructure
a, (b, c), d = 1, [2, 3], 4 binds b/c from the inner typed array via
sp_IntArray_get (a scalar), assigned directly to the b/c locals. When those
locals are widened to poly (promote mode) the scalar lands in a sp_RbVal slot.
Box the element to the inner array's element type when the target slot is
poly. Fixes bundle_misc_b.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- b36b0b0b79da
- Parent
- 4f9a7187ce3b
src/codegen_stmt.cmodifiedView file
@@ -3602,12 +3602,21 @@
36023602
if (!k) { unsupported(c, id, "multiple assignment nested target"); continue; }36033603
int inn2 = 0;36043604
const int *inner_lefts = nt_arr(nt, lefts[i], "lefts", &inn2);3605+
TyKind elemty = !strcmp(k, "Int") ? TY_INT : !strcmp(k, "Float") ? TY_FLOAT3606+
: !strcmp(k, "Str") ? TY_STRING : TY_POLY;36053607
for (int j = 0; j < inn2; j++) {36063608
const char *ilty2 = inner_lefts ? nt_type(nt, inner_lefts[j]) : NULL;36073609
if (!ilty2 || strcmp(ilty2, "LocalVariableTargetNode")) { unsupported(c, id, "multiple assignment nested target"); continue; }3610+
const char *inm = nt_str(nt, inner_lefts[j], "name");3611+
LocalVar *ilv = inm ? scope_local(comp_scope_of(c, inner_lefts[j]), inm) : NULL;3612+
char getexpr[80]; snprintf(getexpr, sizeof getexpr, "sp_%sArray_get(_t%d, %d)", k, tmps[i], j);36083613
emit_indent(b, indent);3609-
buf_printf(b, "lv_%s = sp_%sArray_get(_t%d, %d);\n",3610-
nt_str(nt, inner_lefts[j], "name"), k, tmps[i], j);3614+
buf_printf(b, "lv_%s = ", inm);3615+
/* box the scalar element into a widened (poly) target slot */3616+
if (ilv && ilv->type == TY_POLY && elemty != TY_POLY)3617+
emit_boxed_text(c, elemty, getexpr, b);3618+
else buf_puts(b, getexpr);3619+
buf_puts(b, ";\n");36113620
}36123621
}36133622
else if (lty && !strcmp(lty, "GlobalVariableTargetNode")) {