Commit eacedad8

eacedad8da2eMerged

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

Description

codegen: unbox a poly method return in a scalar poly-dispatch slot

The zero-arg poly method dispatch fixes its result slot to mrb_int for a length-like call (infer hardcodes length/size on a poly receiver to int), but a user class whose method widened its return to poly (e.g. promote-mode def length; 99; end) made that case assign a sp_RbVal to the mrb_int slot. The box direction (scalar method -> poly slot) was handled; add the inverse (poly method -> scalar slot) via emit_unbox_text. Fixes poly_dispatch_builtin_all, poly_dispatch_ptr_array, bundle_class_10, bundle_classd_28.

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

Details

Commit
eacedad8da2e
Parent
5667190e6fac

src/codegen_call.cmodifiedView file

@@ -8213,8 +8213,12 @@
82138213 buf_printf(b, " case %d: ", k);
82148214 if (method_is_void(&c->scopes[mi])) buf_puts(b, call); /* void: no usable value */
82158215 else {
8216+ TyKind slotty = is_scalar_ret(ret) ? ret : TY_INT;
82168217 buf_printf(b, "_t%d = ", tr);
82178218 if (ret == TY_POLY && c->scopes[mi].ret != TY_POLY) emit_boxed_text(c, c->scopes[mi].ret, call, b);
8219+ /* The slot is scalar (e.g. a length dispatch fixed to mrb_int) but
8220+ this class's method widened its return to poly: coerce down. */
8221+ else if (ret != TY_POLY && c->scopes[mi].ret == TY_POLY) emit_unbox_text(c, slotty, call, b);
82188222 else buf_puts(b, call);
82198223 }
82208224 buf_puts(b, "; break;");