Commit 5e9604f4

5e9604f42efcMerged

Ryan Seys <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): dispatch .call on anonymous proc receiver

proc { ... }.call — where the receiver is the inline proc { ... } call itself rather than a local variable holding the proc — fell through to warn_unresolved_call ("cannot resolve call to 'call' on proc"), and the proc body was never invoked. compile_dot_call_expr only matched LocalVariableReadNode receivers and emitted sp_proc_call(lv_<name>, ...); any other recv shape was unhandled.

Fix: after the LocalVariableReadNode special-case, fall through to a generic branch keyed on infer_type(recv) == "proc". Compile the receiver expression and feed it to sp_proc_call with the same arg-array packing convention used for the local-variable path. The check is node-shape-agnostic, so any receiver whose inferred type is proc routes through the same emitter.

Test (test/proc_anon_dot_call.rb) exercises four receiver shapes that all funnel through the new branch:

  • Anonymous proc literal .call (CallNode receiver)
  • Anonymous proc with args (CallNode receiver, arity 1)
  • Method returning proc, immediately called (factory pattern)
  • Ternary returning proc (IfNode receiver with proc-unified arms)

Out-of-scope shapes documented in the fixture header:

  • lambda { ... }.call — separate compile_lambda_call_expr handler.
  • @ivar = proc { ... }; @ivar.call — pre-existing ivar/proc codegen gap (sp_Proc* doesn't fit the ivar slot in master).
  • $global = proc { ... }; $global.call — unverified inference.
  • [procs].each(&:call) — Symbol#to_proc unsupported in master; addressed by rs-no-recv-io-expr-bridge.

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

Details

Commit
5e9604f42efc
Parent
d5b20a0db9db

spinel_codegen.rbmodifiedView file

@@ -13011,6 +13011,20 @@
1301113011 return "sp_proc_call(lv_" + rname + ", (mrb_int[]){" + ca + "})"
1301213012 end
1301313013 end
13014+
13015+ # Anonymous-proc-receiver dispatch — `proc { ... }.call`, or any
13016+ # expression chain whose inferred type is `proc` (e.g.
13017+ # `factory().call`). The LocalVariableReadNode branch above handles
13018+ # the named-proc case directly; this generic branch compiles the
13019+ # receiver expression and feeds it to sp_proc_call, using the same
13020+ # arg-array packing convention.
13021+ if infer_type(recv) == "proc"
13022+ ca_anon = compile_call_args(nid)
13023+ if ca_anon == ""
13024+ ca_anon = "0"
13025+ end
13026+ return "sp_proc_call(" + compile_expr(recv) + ", (mrb_int[]){" + ca_anon + "})"
13027+ end
1301413028 end
1301513029 ""
1301613030 end