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
return 1 end end # Bare `m { ... }` inside another method body of the same # class — `m` is a sibling instance method, lookup happens on # @current_class_idx (and its ancestors). compile_yield_method # _call_stmt synthesizes `self` for rc when recv < 0. if @current_class_idx >= 0 ci_self = @current_class_idx if try_yield_or_trampoline_dispatch(nid, recv, ci_self, mname) == 1 return 1 end pwalk = ci_self while @cls_parents[pwalk] != "" pci = find_class_idx(@cls_parents[pwalk]) if pci < 0 break end if try_yield_or_trampoline_dispatch(nid, recv, pci, mname) == 1 return 1 end pwalk = pci end end end # Class method with yield, or an arity-0 instance_eval trampoline. # The direct-class and parent-class lookups share the same dispatch end recv = @nd_receiver[nid] rc = compile_expr_gc_rooted(recv) if recv < 0 # Implicit self (bare `m { ... }` inside another method body # of the same class). rc = "self" else rc = compile_expr_gc_rooted(recv) end bodies = @cls_meth_bodies[cci].split(";") bid = -1test/yield_method_call_in_method_body.rbaddedView file
Loading diff…
test/yield_method_call_in_method_body.rb.expectedaddedView file
Loading diff…