Commit 20269ccf

20269ccf9c71Merged

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

Description

analyze/codegen: &block param escape as sp_Proc * (poly_proc_call)

When a method captures its &block parameter as a value (e.g., def wrap(&block); block; end), the LocalVariableReadNode for the &block name now returns TY_PROC when the method does not inline the block (yields==0).

Codegen changes:

  • emit_method_signature: adds sp_Proc *lv_ as extra parameter when blk_param is set and yields==0 (escaping block)
  • emit_dispatch: accepts blk_node, pre-evaluates the block as a proc literal and passes it; passes NULL when no block at call site
  • emit_proc_literal / proc_params_node / proc_body_node: handle BlockNode directly (not just proc/lambda CallNode)
  • proc.call with TY_POLY result: box the mrb_int return into sp_RbVal
  • Restrict proc-literal shortcut to actual proc/lambda/Proc.new calls (was matching any TY_PROC-returning call with a block)

Fixes poly_proc_call in bundle_classd_26.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
20269ccf9c71
Parent
3c2129b4a6ec

src/analyze.cmodifiedView file

@@ -1498,8 +1498,15 @@
14981498 if (!strcmp(ty, "LocalVariableReadNode")) {
14991499 const char *nm = nt_str(nt, id, "name");
15001500 Scope *s = comp_scope_of(c, id);
1501+ /* &block param that escapes (not yield-inlined): the LocalVar slot type is
1502+ TY_UNKNOWN, but the value is a Proc object when the method does not inline
1503+ the block (yields==0). Return TY_PROC so callers can type the return value. */
1504+ if (nm && s && s->blk_param && s->blk_param[0] && !strcmp(nm, s->blk_param)
1505+ && !s->yields)
1506+ return TY_PROC;
15011507 LocalVar *lv = nm ? scope_local(s, nm) : NULL;
1502- return lv ? lv->type : TY_UNKNOWN;
1508+ if (lv) return lv->type;
1509+ return TY_UNKNOWN;
15031510 }
15041511 if (!strcmp(ty, "GlobalVariableReadNode")) {
15051512 const char *nm = nt_str(nt, id, "name");