Commit 46129aa5

46129aa59c6cMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): yield-method dispatch on implicit self in method body

Calling a yield-using method on implicit self from inside another instance method dropped the literal block — the call site emitted sp_<C>_<m>(self, args) against a signature that wanted the trailing _block / _benv pair. The same call from top-level worked because the recv<0 branch only consulted @meth_has_yield (top-level only), and the recv>=0 branch was the only one that checked the class's method table.

Add a third branch: when recv<0 inside a class method body (@current_class_idx >= 0), look up the method on the current class and walk ancestors via try_yield_or_trampoline_dispatch — same shape as the explicit-recv branch. compile_yield_method_call_stmt now synthesizes self for rc when @nd_receiver[nid] < 0 instead of trying to compile_expr the missing recv.

Fixes #248

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

Details

Commit
46129aa59c6c
Parent
5f895ce7fc3d

spinel_codegen.rbmodifiedView file

@@ -27024,6 +27024,27 @@
2702427024 return 1
2702527025 end
2702627026 end
27027+ # Bare `m { ... }` inside another method body of the same
27028+ # class — `m` is a sibling instance method, lookup happens on
27029+ # @current_class_idx (and its ancestors). compile_yield_method
27030+ # _call_stmt synthesizes `self` for rc when recv < 0.
27031+ if @current_class_idx >= 0
27032+ ci_self = @current_class_idx
27033+ if try_yield_or_trampoline_dispatch(nid, recv, ci_self, mname) == 1
27034+ return 1
27035+ end
27036+ pwalk = ci_self
27037+ while @cls_parents[pwalk] != ""
27038+ pci = find_class_idx(@cls_parents[pwalk])
27039+ if pci < 0
27040+ break
27041+ end
27042+ if try_yield_or_trampoline_dispatch(nid, recv, pci, mname) == 1
27043+ return 1
27044+ end
27045+ pwalk = pci
27046+ end
27047+ end
2702727048 end
2702827049 # Class method with yield, or an arity-0 instance_eval trampoline.
2702927050 # The direct-class and parent-class lookups share the same dispatch
@@ -31240,7 +31261,13 @@
3124031261 end
3124131262
3124231263 recv = @nd_receiver[nid]
31243- rc = compile_expr_gc_rooted(recv)
31264+ if recv < 0
31265+ # Implicit self (bare `m { ... }` inside another method body
31266+ # of the same class).
31267+ rc = "self"
31268+ else
31269+ rc = compile_expr_gc_rooted(recv)
31270+ end
3124431271
3124531272 bodies = @cls_meth_bodies[cci].split(";")
3124631273 bid = -1