Commit d9c41d3f
d9c41d3f3abeMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Array#zip with block, fix each_with_index poly-param boxing
- Add zip(other) { |a, b| } block form for typed and poly arrays
- Infer zip block param types in analyze so outer vars widen to poly
- Fix each_with_index: box element when outer local is TY_POLY
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- d9c41d3f3abe
- Parent
- de8df958c924
src/analyze.cmodifiedView file
@@ -3339,6 +3339,25 @@
33393339
continue;33403340
}33413341
3342+
/* array.zip(other) { |a, b| } binds element of recv + element of other */3343+
if (!strcmp(name, "zip") && ty_is_array(rt)) {3344+
Scope *zs = comp_scope_of(c, block);3345+
LocalVar *ep0 = scope_local_intern(zs, p0); ep0->is_block_param = 1;3346+
TyKind em0 = ty_unify(ep0->type, ty_array_elem(rt));3347+
if (em0 != ep0->type) { ep0->type = em0; changed = 1; }3348+
const char *zp1 = block_param_name(c, block, 1);3349+
if (zp1) {3350+
int zargs = nt_ref(nt, id, "arguments");3351+
int zargc = 0; const int *zargv = zargs >= 0 ? nt_arr(nt, zargs, "arguments", &zargc) : NULL;3352+
TyKind et2 = (zargc > 0 && zargv && ty_is_array(infer_type(c, zargv[0])))3353+
? ty_array_elem(infer_type(c, zargv[0])) : ty_array_elem(rt);3354+
LocalVar *ep1 = scope_local_intern(zs, zp1); ep1->is_block_param = 1;3355+
TyKind em1 = ty_unify(ep1->type, et2);3356+
if (em1 != ep1->type) { ep1->type = em1; changed = 1; }3357+
}3358+
continue;3359+
}3360+
33423361
/* array.each_with_object(init) { |x, acc| } binds element + accumulator */33433362
if (!strcmp(name, "each_with_object") && ty_is_array(rt)) {33443363
Scope *es = comp_scope_of(c, block);src/codegen.cmodifiedView file
Loading diff…