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
buf_puts(b, ";\n"); return; } /* A poly cell (an int local widened to poly in promote mode, then captured): route the arithmetic through the tag-dispatching sp_poly_<op>, boxing the rhs. Bitwise/shift coerce to int and re-box, mirroring the non-celled poly op-assign path. */ if (t == TY_POLY) { const char *pfn = !strcmp(op, "+") ? "sp_poly_add" : !strcmp(op, "-") ? "sp_poly_sub" : !strcmp(op, "*") ? "sp_poly_mul" : !strcmp(op, "/") ? "sp_poly_div" : !strcmp(op, "%") ? "sp_poly_mod" : NULL; if (pfn) { buf_printf(b, "%s(", pfn); emit_local_ref(c, id, nm, b); buf_puts(b, ", "); emit_boxed(c, v, b); buf_puts(b, ");\n"); return; } if (!strcmp(op, "<<") || !strcmp(op, ">>") || !strcmp(op, "|") || !strcmp(op, "&") || !strcmp(op, "^")) { TyKind vt = comp_ntype(c, v); buf_puts(b, "sp_box_int((sp_poly_to_i("); emit_local_ref(c, id, nm, b); buf_printf(b, ") %s (", op); if (vt == TY_POLY) { buf_puts(b, "sp_poly_to_i("); emit_expr(c, v, b); buf_puts(b, ")"); } else emit_expr(c, v, b); buf_puts(b, ")));\n"); return; } } const char *fn = int_arith_fn(op); if (fn) { int isdivmod = !strcmp(op, "/") || !strcmp(op, "%");