Commit 360eab89
360eab89cf40Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
codegen: box a begin/rescue scalar result feeding a poly tail slot under promote
A tail-position begin/rescue computes its value into a scalar temp, then emits it through emit_tail_lead (a return or an outer result-var assignment). When the tail slot is poly -- a widened return type, or an outer poly result var -- box the scalar temp to match. Unblocks begin_rescue_else_clause, method_level_rescue_return.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 360eab89cf40
- Parent
- 435ea3b76984
src/codegen_stmt.cmodifiedView file
@@ -3898,7 +3898,16 @@
38983898
int sp = g_result_poly; g_result_poly = (rt == TY_POLY);38993899
emit_begin(c, id, b, indent, rv);39003900
g_result_poly = sp;3901-
emit_indent(b, indent); emit_tail_lead(b); buf_printf(b, "_t%d;\n", t);3901+
emit_indent(b, indent); emit_tail_lead(b);3902+
/* the begin's scalar result temp feeds a poly tail slot (return type or an3903+
outer poly result var widened under promote): box it to match. */3904+
int target_poly = g_result_var ? g_result_poly : (g_ret_type == TY_POLY);3905+
if (target_poly && rt != TY_POLY) {3906+
char ex[24]; snprintf(ex, sizeof ex, "_t%d", t);3907+
Buf bx; memset(&bx, 0, sizeof bx); emit_boxed_text(c, rt, ex, &bx);3908+
buf_printf(b, "%s;\n", bx.p ? bx.p : "sp_box_nil()"); free(bx.p);3909+
}3910+
else buf_printf(b, "_t%d;\n", t);39023911
return;39033912
}39043913
/* Non-scalar (e.g. TY_VOID when body diverges with raise or return):