Commit 5914c9e1
5914c9e1bef6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified
Description
codegen: box the throw value for a poly-typed catch
A catch whose result type is poly (e.g. its block's value is poly, as in
catch(:t) { Fiber.yield }) emitted the throw-caught arm as
_t = sp_catch_val[top], assigning an mrb_int to an sp_RbVal temp -- a hard C
compile error. The ptr/non-ptr split didn't cover TY_POLY. This surfaced as the
"catch/throw inside a fiber body" failure noted on #1474.
Add a TY_POLY arm that boxes the caught int (sp_box_int). The common shape is a poly block return with no matching throw, where the arm is dead; a throw with an int value to a poly catch now boxes correctly. (Carrying a non-int thrown value to a poly catch remains a limitation of the int-only throw value channel.)
Verified: catch in a fiber body and a poly catch with an int throw both match CRuby; existing catch/throw tests unchanged.
Gates: 952 tests pass, optcarrot checksum 59662.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 5914c9e1bef6
- Parent
- 5a3daaa3d823
src/codegen_call.cmodifiedView file
buf_printf(g_pre, "_t%d = (", t); emit_ctype(c, bt, g_pre); buf_printf(g_pre, ")(uintptr_t)sp_catch_val[sp_catch_top];\n"); } else if (bt == TY_POLY) { /* A poly-typed catch (e.g. its block's value is poly): the mrb_int value channel can't carry a tagged value, so box the thrown int. Common shape is a poly block return with no matching throw, where this arm is dead; a thrown non-int to a poly catch is a separate limitation of the int-only throw channel. */ buf_printf(g_pre, "_t%d = sp_box_int(sp_catch_val[sp_catch_top]);\n", t); } else { buf_printf(g_pre, "_t%d = sp_catch_val[sp_catch_top];\n", t); }test/catch_in_fiber_body.rbaddedView file
Loading diff…