Commit 5a7a9672

5a7a9672f859Merged

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

Description

feat(iter): tap/then expression position + Enumerable#filter_map

Two value-position iterator gaps (to be split):

  • tap / then / yield_self in expression position: tap runs the block for its side effect and yields the (unchanged) receiver; then yields the block's value. Works across receiver types, so p(x.tap{...}) and a.map{}.tap{} chains no longer hit 'unsupported call'.

  • Enumerable#filter_map: had block-param typing but no codegen/result-type. A dedicated emitter builds a boxed result array keeping each truthy block value (sp_poly_truthy); the call type infers to a poly array. Output matches CRuby for nilable (expr if cond) and plain-transform bodies. Array receivers; range filter_map is a later slice.

Details

Commit
5a7a9672f859
Parent
9b8de269b07f

src/analyze_infer.cmodifiedView file

@@ -1478,6 +1478,7 @@
14781478 !strcmp(name, "find") || !strcmp(name, "detect"))
14791479 return ty_array_elem(rt); /* returns an element */
14801480 if (!strcmp(name, "partition")) return TY_POLY_ARRAY; /* [[truthy...],[falsy...]] */
1481+ if (!strcmp(name, "filter_map")) return TY_POLY_ARRAY; /* map then drop falsy */
14811482 }
14821483 /* grep/grep_v without a block filter by `pattern === e`, preserving the
14831484 receiver's array type. */