Repository navigation
Commit eb7a3a2
Handle the SCOPE node of a block like an ITER node
For an ArgumentError raised when calling a lambda or a method defined
with define_method, the backtrace location of the callee is the block
frame itself, so the node of that location is the node of the block iseq.
Ruby 4.1 changes RubyVM::InstructionSequence#syntax_tree for a block iseq
to return the node that is compiled into the iseq: the Ruby::Prism::BlockNode
with prism, or the SCOPE node with parse.y, instead of the method call the
block is passed to [Feature #21795]. Thread::Backtrace::Location#syntax_tree
builds on that method, so for such a location it now returns the SCOPE
node under parse.y, where it returned the ITER node before (with prism it
already returned the BlockNode). Without this change, the callee snippet
pointing at the opening `{` or `do` is not displayed anymore under parse.y:
wrong number of arguments (given 1, expected 0) (ArgumentError)
caller: test.rb:3
| v.call(1)
^^^^^
callee: test.rb:1
| v = lambda { }
^
The ITER node is the method call with its block, and its second child is
the SCOPE node of the block, so a SCOPE node can be spotted exactly like
an ITER node, by looking at the SCOPE node directly. The ITER case is
kept for older Rubies, where RubyVM::AbstractSyntaxTree.of is used.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>1 parent ae50da6 commit eb7a3a2
1 file changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
| 273 | + | |
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| |||
727 | 727 | | |
728 | 728 | | |
729 | 729 | | |
730 | | - | |
| 730 | + | |
731 | 731 | | |
732 | 732 | | |
733 | 733 | | |
| |||
0 commit comments