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— separatecompile_lambda_call_exprhandler.@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
return "sp_proc_call(lv_" + rname + ", (mrb_int[]){" + ca + "})" end end # Anonymous-proc-receiver dispatch — `proc { ... }.call`, or any # expression chain whose inferred type is `proc` (e.g. # `factory().call`). The LocalVariableReadNode branch above handles # the named-proc case directly; this generic branch compiles the # receiver expression and feeds it to sp_proc_call, using the same # arg-array packing convention. if infer_type(recv) == "proc" ca_anon = compile_call_args(nid) if ca_anon == "" ca_anon = "0" end return "sp_proc_call(" + compile_expr(recv) + ", (mrb_int[]){" + ca_anon + "})" end end "" endtest/proc_anon_dot_call.rbaddedView file
Loading diff…
test/proc_anon_dot_call.rb.expectedaddedView file
Loading diff…