Commit bcefdb4d
bcefdb4d2c38Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
poly.call returns int: array-of-Methods dispatch (#215)
A bound Method flowing through a poly array element ('[m1,m2].each {|bm| bm.call(x)}') reaches the poly .call path; analyze now types poly.call as the mrb_int the runtime ABI returns (when no user 'call' method exists), so puts/assign accept it. Fixes bound_method_obj_recv.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- bcefdb4d2c38
- Parent
- badd0ef6695a
src/analyze.cmodifiedView file
@@ -561,6 +561,16 @@
561561
if (!strcmp(name, "name")) return TY_STRING;562562
if (!strcmp(name, "arity")) return TY_INT;563563
}564+
/* <poly>.call(args): a boxed Proc/Method called through the runtime ABI,565+
which returns mrb_int. (Skip when a user class defines `call`: that goes566+
through normal dispatch and returns the method's own type.) */567+
if (recv >= 0 && rt == TY_POLY &&568+
(!strcmp(name, "call") || !strcmp(name, "()"))) {569+
int has_user_call = 0;570+
for (int k = 0; k < c->nclasses && !has_user_call; k++)571+
if (comp_method_in_class(c, k, "call") >= 0) has_user_call = 1;572+
if (!has_user_call) return TY_INT;573+
}564574
565575
/* proc {} / lambda {} / Proc.new {} -> a first-class Proc value */566576
if (is_proc_literal(c, id)) return TY_PROC;