Commit 599e0da6
599e0da6e4e7Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Fix block params beyond yield arity typed as TY_UNKNOWN
In infer_block_params, after binding yield args to block params:
-
Scan all yields in the method to find the minimum arity. Block params at index >= min_arity can receive nil from any yield, so widen them to TY_POLY. This handles both
yield(0 args) with multi-param blocks AND multi-yield methods where some yields provide fewer args than the block expects. -
In emit_block_invoke (codegen), when a block param is TY_POLY but the yield arg is a scalar (int/string/etc), box the value before assigning, matching emit_iter_param_assign's behavior.
Together these fix i997 (yield arity mismatch, e.g. show2 yields nothing but block has |a, b|, or multi yields 1 or 2 args with block |p, q|).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 599e0da6e4e7
- Parent
- aa049e24057b
src/analyze.cmodifiedView file
TyKind m = ty_unify(lv->type, infer_type(c, yargs[k])); if (m != lv->type) { lv->type = m; changed = 1; } } /* Params beyond the first yield's arity might still be nil if there are other yields with fewer args. Find the min yield arity. */ int min_yc = yc; for (int _yi = 0; _yi < nt->count; _yi++) { if (!nt_type(nt, _yi) || strcmp(nt_type(nt, _yi), "YieldNode")) continue; if (c->nscope[_yi] != mi) continue; int _ya = nt_ref(nt, _yi, "arguments"); int _yc = 0; if (_ya >= 0) nt_arr(nt, _ya, "arguments", &_yc); if (_yc < min_yc) min_yc = _yc; } /* Block params at index >= min_yc can receive nil — widen to poly. */ for (int k = min_yc; ; k++) { const char *bp = block_param_name(c, block, k); if (!bp) break; LocalVar *lv = scope_local_intern(bs, bp); lv->is_block_param = 1; TyKind m = ty_unify(lv->type, TY_POLY); if (m != lv->type) { lv->type = m; changed = 1; } } continue; } }src/codegen.cmodifiedView file
Loading diff…