Commit 0d14102f

0d14102f82f0Merged

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

Description

analyze: type each_cons block params as elements for multi-param blocks

arr.each_cons(n).map { |a, b| ... } typed every block param as the whole n-window array, even with several params, while the codegen bound each param to a window ELEMENT (sp_IntArray_get(window, i + pj)). The mismatch made a + b compile as array concat and lv_a = <element> a pointer-from-int error, so non-trivial bodies were rejected or miscompiled.

each_cons and each_slice share the same param semantics: a single param |w| binds the whole window/slice (an array); several params |a, b| (or a single destructured |(a, b)|) split it into element-typed params. Drop the each_cons-only branch that forced the array type so each_cons follows the same rule, matching its codegen.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
0d14102f82f0
Parent
3d4efd9a07a7

src/analyze_pass.cmodifiedView file

@@ -3143,15 +3143,14 @@
31433143 nt_ref(nt, recv, "block") < 0) {
31443144 int es_recv2 = nt_ref(nt, recv, "receiver");
31453145 TyKind arr_t2 = es_recv2 >= 0 ? infer_type(c, es_recv2) : TY_UNKNOWN;
3146- int is_cons2 = !strcmp(nt_str(nt, recv, "name"), "each_cons");
31473146 if (ty_is_array(arr_t2)) {
31483147 Scope *es2 = comp_scope_of(c, block);
31493148 int np2 = 0; while (block_param_name(c, block, np2)) np2++;
3150- /* each_cons binds the n-window (array); each_slice binds the slice
3151- (array) for a single param `|s|`, or destructures into elements when
3152- there are several params `|a, b|`. A single destructured param
3153- `|(a, b)|` over either splits the window/slice into its elements. */
3154- TyKind bp_t2 = is_cons2 ? arr_t2 : (np2 == 1 ? arr_t2 : ty_array_elem(arr_t2));
3149+ /* each_cons and each_slice bind the n-window / slice (an array) for a
3150+ single param `|w|`, or destructure it into elements for several
3151+ params `|a, b|` (matching the codegen, which binds element pj when
3152+ np > 1). A single destructured param `|(a, b)|` splits it likewise. */
3153+ TyKind bp_t2 = (np2 == 1 ? arr_t2 : ty_array_elem(arr_t2));
31553154 if (bp_t2 != TY_UNKNOWN) {
31563155 if (np2 == 0 && block_param_is_multi(c, block, 0)) {
31573156 /* |(a, b)| destructuring: each leaf gets element type */