Commit 1f14a304

1f14a304d288Merged

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

Description

Numeric#step without a block materializes an array

A blockless numeric step (1.0.step(3.0, 0.5), 1.step(5)) now produces an int or float array instead of an unhandled enumerator, so a following .to_a / .inspect works. The element kind follows the operands; the float form uses the same drift-bounded iteration count as the block form.

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

Details

Commit
1f14a304d288
Parent
9eebaacd9502

src/analyze.cmodifiedView file

@@ -755,6 +755,14 @@
755755 if ((!strcmp(name, "<<") || !strcmp(name, "concat") || !strcmp(name, "prepend")) && argc == 1)
756756 return TY_STRING;
757757 }
758+ /* numeric.step(...) without a block materializes the sequence as an array */
759+ if (recv >= 0 && ty_is_numeric(rt) && !strcmp(name, "step") && nt_ref(nt, id, "block") < 0) {
760+ int args = nt_ref(nt, id, "arguments");
761+ int sc = 0; const int *sv = args >= 0 ? nt_arr(nt, args, "arguments", &sc) : NULL;
762+ int isf = (rt == TY_FLOAT) || (sc >= 1 && infer_type(c, sv[0]) == TY_FLOAT) ||
763+ (sc >= 2 && infer_type(c, sv[1]) == TY_FLOAT);
764+ return isf ? TY_FLOAT_ARRAY : TY_INT_ARRAY;
765+ }
758766 /* integer receiver methods */
759767 if (recv >= 0 && rt == TY_INT) {
760768 if (!strcmp(name, "ceil") || !strcmp(name, "floor") ||