Commit 6c319359

6c31935943d9Merged

Ryan Seys <[email protected]> · 5 months ago · 7 files · +2 added · ~5 modified

Description

feat(iter): chunk_while { |a,b| } .to_a grouping

Details

Commit
6c31935943d9
Parent
d30ff38bc04b

src/analyze_infer.cmodifiedView file

@@ -320,6 +320,15 @@
320320 if (!strcmp(name, "respond_to?")) return TY_BOOL;
321321 }
322322
323+ /* int_array.chunk_while { |a, b| } .to_a -> a poly array of int-array runs */
324+ if (recv >= 0 && !strcmp(name, "to_a") &&
325+ nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "CallNode") &&
326+ nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "chunk_while") &&
327+ nt_ref(nt, recv, "block") >= 0) {
328+ int pr = nt_ref(nt, recv, "receiver");
329+ if (pr >= 0 && infer_type(c, pr) == TY_INT_ARRAY) return TY_POLY_ARRAY;
330+ }
331+
323332 /* an empty array literal used directly as a receiver (`[].flatten`) has no
324333 usage to fold an element type from; treat it as an empty poly array so
325334 array methods dispatch instead of falling through to unresolved. */