Commit 8be0a442

8be0a442c750Merged

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

Description

poly.length/size handles string and array tags

The poly dispatch now fires for length/size/count even with no user class defining them, and a string-tagged poly answers by its char count before the cls_id switch (which still covers built-in arrays and user classes). Fixes poly.length on a string while keeping poly dispatch to a user-defined length.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
8be0a442c750
Parent
c15716c6d7b7

src/analyze.cmodifiedView file

@@ -323,7 +323,7 @@
323323 return TY_BOOL;
324324 if (rt == TY_POLY) {
325325 if (!strcmp(name, "to_s") || !strcmp(name, "inspect")) return TY_STRING;
326- if (!strcmp(name, "to_i")) return TY_INT;
326+ if (!strcmp(name, "to_i") || !strcmp(name, "length") || !strcmp(name, "size")) return TY_INT;
327327 if (!strcmp(name, "to_f")) return TY_FLOAT;
328328 /* poly method dispatch: unify the return type over every class that
329329 defines `name` (the runtime cls_id picks the impl). */