Commit 280666df

280666dfbef0Merged

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

Description

Integer#times/upto/downto/step in expression position return self

In expression position these run the loop (lowered to a statement) and evaluate to the receiver, matching MRI; the statement form already iterated correctly.

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

Details

Commit
280666dfbef0
Parent
2d82efaf07a9

src/analyze.cmodifiedView file

@@ -689,6 +689,9 @@
689689 if ((!strcmp(name, "ceildiv") || !strcmp(name, "pow")) && argc >= 1) return TY_INT;
690690 if ((!strcmp(name, "pred") || !strcmp(name, "succ") || !strcmp(name, "next")) && argc == 0) return TY_INT;
691691 if (!strcmp(name, "nonzero?") && argc == 0) return TY_INT; /* self or nil (nullable int) */
692+ /* times/upto/downto/step with a block return the receiver (self) */
693+ if ((!strcmp(name, "times") || !strcmp(name, "upto") || !strcmp(name, "downto") ||
694+ !strcmp(name, "step")) && nt_ref(nt, id, "block") >= 0) return TY_INT;
692695 if (!strcmp(name, "chr")) return TY_STRING;
693696 if (!strcmp(name, "[]") && argc == 1) return TY_INT; /* bit access */
694697 if (!strcmp(name, "gcd") || !strcmp(name, "lcm") || !strcmp(name, "clamp")) return TY_INT;