Commit 1e3634da

1e3634da9cf1Merged

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

Description

Array#product rendered via an inline inspect chain

[a, b].product([c, d]).inspect (optionally through .to_a) now renders the Cartesian product as a nested-array string using sp_IntArray_product and the IntArrayPtrArray inspect helper. The product result has no first-class type yet, so only this inline inspect chain is handled; the empty-array operand is accepted.

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

Details

Commit
1e3634da9cf1
Parent
8d3205ea401e

src/analyze.cmodifiedView file

@@ -763,6 +763,17 @@
763763 if ((!strcmp(name, "<<") || !strcmp(name, "concat") || !strcmp(name, "prepend")) && argc == 1)
764764 return TY_STRING;
765765 }
766+ /* <int_array>.product(<int_array>)[.to_a].inspect -> a string */
767+ if (!strcmp(name, "inspect") && argc == 0 && recv >= 0) {
768+ int pr = recv;
769+ if (nt_type(nt, pr) && !strcmp(nt_type(nt, pr), "CallNode") &&
770+ nt_str(nt, pr, "name") && !strcmp(nt_str(nt, pr, "name"), "to_a"))
771+ pr = nt_ref(nt, pr, "receiver");
772+ if (pr >= 0 && nt_type(nt, pr) && !strcmp(nt_type(nt, pr), "CallNode") &&
773+ nt_str(nt, pr, "name") && !strcmp(nt_str(nt, pr, "name"), "product"))
774+ return TY_STRING;
775+ }
776+
766777 /* numeric.step(...) without a block materializes the sequence as an array */
767778 if (recv >= 0 && ty_is_numeric(rt) && !strcmp(name, "step") && nt_ref(nt, id, "block") < 0) {
768779 int args = nt_ref(nt, id, "arguments");