Commit 2631d800

2631d800a7d8Merged

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

Description

define_method block params become the method's params

A single define_method(:m) { |args| ... } (including the &:sym-rewritten { |_spx| _spx.to_s } form) registered the body but not the block's parameters, so call-site arg types never bound to them. Register the block requireds as the method params.

Fixes symbol_to_proc_after_positional.

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

Details

Commit
2631d800a7d8
Parent
abedb3d06e89

src/analyze.cmodifiedView file

@@ -2873,6 +2873,16 @@
28732873 int dm_new_idx = c->nscopes - 1;
28742874 dm_s->body = nt_ref(c->nt, dm_blk, "body");
28752875 dm_s->class_id = class_id;
2876+ /* the block's params are the defined method's params (e.g. the
2877+ `&:to_s`-rewritten `{ |_spx| _spx.to_s }`'s _spx). */
2878+ int dm_pn = nt_ref(c->nt, dm_blk, "parameters");
2879+ int dm_inner = dm_pn >= 0 ? nt_ref(c->nt, dm_pn, "parameters") : -1;
2880+ int dm_pnode = dm_inner >= 0 ? dm_inner : dm_pn;
2881+ int dm_rn = 0; const int *dm_reqs = dm_pnode >= 0 ? nt_arr(c->nt, dm_pnode, "requireds", &dm_rn) : NULL;
2882+ for (int p = 0; p < dm_rn; p++) {
2883+ const char *pnm = nt_str(c->nt, dm_reqs[p], "name");
2884+ if (pnm) scope_add_param(dm_s, pnm, -1);
2885+ }
28762886 child = dm_new_idx;
28772887 }
28782888 }