Commit 5396dc78

5396dc78c1f4Merged

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

Description

codegen: box the rhs of an object op-assign dispatching to a user operator

slot OP= rhs on an object slot with a user-defined OP hoists rhs into a temp typed from OP's first param. When that param widened to poly (promote mode) the temp is sp_RbVal but the scalar rhs was emitted unboxed (sp_RbVal _t = 5LL). Box it when the param is poly and the rhs is scalar, in both the ivar and local op-assign forms. Fixes op_assign_user_operator.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
5396dc78c1f4
Parent
b36b0b0b79da

src/codegen_stmt.cmodifiedView file

@@ -685,10 +685,13 @@
685685 Scope *ms2 = &c->scopes[mi2];
686686 LocalVar *p2 = ms2->nparams >= 1 ? scope_local(ms2, ms2->pnames[0]) : NULL;
687687 int atmp2 = ++g_tmp;
688+ TyKind p2t = p2 ? p2->type : comp_ntype(c, v);
688689 emit_indent(g_pre, g_indent);
689- emit_ctype(c, p2 ? p2->type : comp_ntype(c, v), g_pre);
690+ emit_ctype(c, p2t, g_pre);
690691 buf_printf(g_pre, " _t%d = ", atmp2);
691- emit_expr(c, v, g_pre);
692+ /* box the rhs when the operator's param widened to poly (promote mode) */
693+ if (p2t == TY_POLY && comp_ntype(c, v) != TY_POLY) emit_boxed(c, v, g_pre);
694+ else emit_expr(c, v, g_pre);
692695 buf_puts(g_pre, ";\n");
693696 buf_printf(b, "lv_%s = sp_%s_%s((sp_%s *)lv_%s, _t%d);\n",
694697 en, c->classes[defcls2].name, mc(ms2->name),
@@ -2910,10 +2913,13 @@
29102913 LocalVar *ip = ims->nparams >= 1 ? scope_local(ims, ims->pnames[0]) : NULL;
29112914 int iatmp = ++g_tmp;
29122915 int ival = nt_ref(nt, id, "value");
2916+ TyKind ipt = ip ? ip->type : comp_ntype(c, ival);
29132917 emit_indent(g_pre, g_indent);
2914- emit_ctype(c, ip ? ip->type : comp_ntype(c, ival), g_pre);
2918+ emit_ctype(c, ipt, g_pre);
29152919 buf_printf(g_pre, " _t%d = ", iatmp);
2916- emit_expr(c, ival, g_pre);
2920+ /* box the rhs when the operator's param widened to poly (promote mode) */
2921+ if (ipt == TY_POLY && comp_ntype(c, ival) != TY_POLY) emit_boxed(c, ival, g_pre);
2922+ else emit_expr(c, ival, g_pre);
29172923 buf_puts(g_pre, ";\n");
29182924 buf_printf(b, "%s = sp_%s_%s((sp_%s *)%s, _t%d);\n",
29192925 ref, c->classes[idefcls].name, mc(ims->name),