Commit de936a0b
de936a0b4a13Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Array#combination with a block
Yield each k-combination of an int_array as a fresh int_array via the existing sp_IntArray_combination helper. analyze binds the block parameter to the array kind.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- de936a0b4a13
- Parent
- e465c05368b1
src/analyze.cmodifiedView file
@@ -2063,6 +2063,14 @@
20632063
continue;20642064
}20652065
2066+
/* array.combination(k) { |c| } binds the k-element sub-array (same kind) */2067+
if (!strcmp(name, "combination") && ty_is_array(rt)) {2068+
LocalVar *lp = scope_local_intern(comp_scope_of(c, block), p0); lp->is_block_param = 1;2069+
TyKind m = ty_unify(lp->type, rt);2070+
if (m != lp->type) { lp->type = m; changed = 1; }2071+
continue;2072+
}2073+
20662074
/* array.each_with_index { |x, i| } binds element + int index */20672075
if (!strcmp(name, "each_with_index") && ty_is_array(rt)) {20682076
Scope *es = comp_scope_of(c, block);src/codegen.cmodifiedView file
Loading diff…