Commit db91c510

db91c5102195Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

instance_eval/exec: bind numbered block params (_1.._N)

recv.instance_eval { _1.method } uses a NumberedParametersNode rather than a ParametersNode with requireds, so the block-param binding never typed _1 and codegen left it unbound. Bind _1.._maximum like positional block params: to the receiver for instance_eval, to the forwarded args for instance_exec.

(test/instance_eval_block_params still errors on a separate, deferred issue: a block param sharing a name with an enclosing local collides because block params are interned in the enclosing scope.)

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

Details

Commit
db91c5102195
Parent
9c5cb739574e

src/analyze.cmodifiedView file

@@ -5893,10 +5893,21 @@
58935893 if (blk < 0) continue;
58945894 int pn = nt_ref(nt, blk, "parameters");
58955895 if (pn < 0) continue;
5896+ Scope *bs = comp_scope_of(c, blk);
5897+ const char *pnty = nt_type(nt, pn);
5898+ if (pnty && !strcmp(pnty, "NumberedParametersNode")) {
5899+ /* `{ _1.method }` : _1.._N all receive self (the receiver). */
5900+ int maxn = (int)nt_int(nt, pn, "maximum", 0);
5901+ for (int k = 1; k <= maxn; k++) {
5902+ char nm[8]; snprintf(nm, sizeof nm, "_%d", k);
5903+ LocalVar *lv = scope_local_intern(bs, nm); lv->is_block_param = 1;
5904+ if (lv->type != rt) { lv->type = rt; changed = 1; }
5905+ }
5906+ continue;
5907+ }
58965908 int inner = nt_ref(nt, pn, "parameters");
58975909 int pnode = inner >= 0 ? inner : pn;
58985910 int rnp = 0; const int *reqs = nt_arr(nt, pnode, "requireds", &rnp);
5899- Scope *bs = comp_scope_of(c, blk);
59005911 for (int k = 0; k < rnp; k++) {
59015912 const char *p = nt_str(nt, reqs[k], "name");
59025913 if (!p) continue;