Commit 9b8de269
9b8de269b07fMerged
Ryan Seys <[email protected]> · 5 months ago · 7 files · +2 added · ~5 modified
Description
feat(iter): each_slice(n).to_a / each_cons(n).to_a + slice map-chain typing
- Fix the each_slice(n).map { |s| ... } chain: a single param binds the whole
slice (sub-array), not an element -- so
.map { |s| s.sum }and identity maps type correctly (previously a C 'pointer to integer' error). each_cons keeps the window; several params still destructure into elements. - Desugar the blockless
each_slice(n).to_a/each_cons(n).to_aenumerator into the equivalent.map { |__s| __s }, reusing the slice/window map-fold -- no full Enumerator object for the common materialize-the-slices idiom.
Details
- Commit
- 9b8de269b07f
- Parent
- 7b996f317369
src/analyze.cmodifiedView file
@@ -1534,6 +1534,7 @@
15341534
ch |= propagate_prep_params(c);15351535
ch |= infer_string_params(c);15361536
ch |= infer_default_param_types(c);1537+
ch |= desugar_enum_chain_to_a(c); /* each_slice(n).to_a -> .map{|s|s} */15371538
ch |= desugar_value_callable_forwards(c); /* &proc -> { |x| proc.call(x) } */15381539
ch |= infer_block_params(c);15391540
ch |= infer_for_index(c);src/analyze_internal.hmodifiedView file
Loading diff…
src/analyze_pass.cmodifiedView file
Loading diff…
src/codegen_fold.cmodifiedView file
Loading diff…
test/each_slice_cons_to_a.rbaddedView file
Loading diff…
test/each_slice_cons_to_a.rb.expectedaddedView file
Loading diff…
test/each_slice_map.rbmodifiedView file
Loading diff…