Commit 90c8e5c4
90c8e5c48b09Merged
Ryan Seys <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): forward &block at self-call sites
m { ... } from inside another method of the same class silently
dropped the literal block. The self-call dispatch path —
compile_no_recv_call_expr's @current_class_idx >= 0 branch —
always emitted sp_C_m(self, ca) with no block tail, so the block
went nowhere and the binary segfaulted in sp_proc_call(NULL, ...).
Reproducer:
class Caller
def kick
inner { puts "hi" }
end
def inner(&block)
block.call
end
end
Caller.new.kick # Ruby: hi / pre-fix Spinel: SIGSEGV
Symmetric to the typed-receiver fix; reuses has_literal_block,
cls_method_has_block_param, build_call_tail, and the
omit_trailing 4th arg of compile_typed_call_args. The new code
is just the same bp/tail template adapted to the self-call form,
which carries self instead of a typed-receiver C-temp.
Test plan
-
make bootstrap(gen2.c == gen3.c) -
make test161/161 pass (160 at base + 1 new) -
test/block_forward_self_call.rbcovers 3 cases — bare self-call, self-call passing arg through to block, self-call inside a loop forwarding a fresh block per iteration.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 90c8e5c48b09
- Parent
- 848774d4ced4
spinel_codegen.rbmodifiedView file
if cidx >= 0 owner = find_method_owner(@current_class_idx, mname) # Look up the method's owning class so we can fill in defaults # from @cls_meth_defaults (issue #49). # from @cls_meth_defaults (issue #49) and check for a &block slot. owner_ci = find_class_idx(owner) owner_midx = -1 if owner_ci >= 0 owner_midx = cls_find_method_direct(owner_ci, mname) end # Omit the trailing &block slot from default-padding when the # callee declares one — we'll fill it explicitly from the # call site's literal block below. has_proc = cls_method_has_block_param(owner_ci, owner_midx) ca = "" if owner_midx >= 0 ca = compile_typed_call_args(nid, owner_ci, owner_midx, 0) ca = compile_typed_call_args(nid, owner_ci, owner_midx, has_proc) else ca = compile_call_args(nid) end if ca != "" return "sp_" + owner + "_" + sanitize_name(mname) + "(self, " + ca + ")" else return "sp_" + owner + "_" + sanitize_name(mname) + "(self)" bp = "" if has_proc == 1 if has_literal_block(nid) == 1 @needs_proc = 1 bp = compile_proc_literal(nid) else # The callee declares &block but the call site provides # none — fill the slot with NULL so the C call has the # right arity. bp = "0" end end return "sp_" + owner + "_" + sanitize_name(mname) + "(self" + build_call_tail(ca, bp) + ")" end # Check attr_readers (bare method call like `x` meaning self.x) readers = @cls_attr_readers[@current_class_idx].split(";")test/block_forward_self_call.rbaddedView file
Loading diff…