Commit 828ca66a

828ca66a0f40Merged

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

Description

codegen: route op-assign on a captured poly cell through sp_poly_

In promote mode an int local widened to poly that is then captured by a proc/block rides a sp_RbVal cell. Compound assignment on such a cell fell through to the int_arith_fn path, emitting sp_int_add(<sp_RbVal>, ...) which fails to typecheck. Add a poly arm mirroring the non-celled poly op-assign: arithmetic dispatches to sp_poly_ (boxing the rhs), bitwise/shift coerce to int and re-box. Fixes closure_capture_float, block_forward_value_callable, bundle_classd_13 in promote mode; inert in default mode (cells are only poly under the promote widen pass).

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

Details

Commit
828ca66a0f40
Parent
b37fff07e5fb

src/codegen_stmt.cmodifiedView file

@@ -580,6 +580,32 @@
580580 buf_puts(b, ";\n");
581581 return;
582582 }
583+ /* A poly cell (an int local widened to poly in promote mode, then captured):
584+ route the arithmetic through the tag-dispatching sp_poly_<op>, boxing the
585+ rhs. Bitwise/shift coerce to int and re-box, mirroring the non-celled
586+ poly op-assign path. */
587+ if (t == TY_POLY) {
588+ const char *pfn = !strcmp(op, "+") ? "sp_poly_add"
589+ : !strcmp(op, "-") ? "sp_poly_sub"
590+ : !strcmp(op, "*") ? "sp_poly_mul"
591+ : !strcmp(op, "/") ? "sp_poly_div"
592+ : !strcmp(op, "%") ? "sp_poly_mod" : NULL;
593+ if (pfn) {
594+ buf_printf(b, "%s(", pfn); emit_local_ref(c, id, nm, b); buf_puts(b, ", ");
595+ emit_boxed(c, v, b); buf_puts(b, ");\n");
596+ return;
597+ }
598+ if (!strcmp(op, "<<") || !strcmp(op, ">>") ||
599+ !strcmp(op, "|") || !strcmp(op, "&") || !strcmp(op, "^")) {
600+ TyKind vt = comp_ntype(c, v);
601+ buf_puts(b, "sp_box_int((sp_poly_to_i("); emit_local_ref(c, id, nm, b);
602+ buf_printf(b, ") %s (", op);
603+ if (vt == TY_POLY) { buf_puts(b, "sp_poly_to_i("); emit_expr(c, v, b); buf_puts(b, ")"); }
604+ else emit_expr(c, v, b);
605+ buf_puts(b, ")));\n");
606+ return;
607+ }
608+ }
583609 const char *fn = int_arith_fn(op);
584610 if (fn) {
585611 int isdivmod = !strcmp(op, "/") || !strcmp(op, "%");