Commit 4c1c7c91

4c1c7c91f155Merged

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

Description

codegen: box a no-block yield into a poly tail slot

A no-block yield in a poly-returning inlined method (e.g. if block_given?; yield x; else; x*2; end) emitted the int sentinel SP_INT_NIL into the inline's poly result temp. Two coordinated fixes: the no-block yield emits sp_box_nil() when its inferred type is poly, and emit_tail_value no longer rewrites a poly sp_box_nil() into the scalar emit_ret_nil(g_ret_type) form when the tail feeds a poly result var (g_result_poly). Fixes block2.

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

Details

Commit
4c1c7c91f155
Parent
709b86a93f4a

src/codegen_expr.cmodifiedView file

@@ -656,7 +656,12 @@
656656 emit_proc_call_args(c, yargc, yargv, b);
657657 return;
658658 }
659- if (g_block_id < 0) { buf_puts(b, "SP_INT_NIL"); return; } /* no block: yield is nil */
659+ if (g_block_id < 0) { /* no block: yield is nil */
660+ /* box the sentinel when the yield value feeds a poly slot (its method
661+ return widened to poly in promote mode) */
662+ buf_puts(b, comp_ntype(c, id) == TY_POLY ? "sp_box_nil()" : "SP_INT_NIL");
663+ return;
664+ }
660665 emit_block_invoke(c, nt_ref(nt, id, "arguments"), b, 0, 1);
661666 return;
662667 }