From 5d9d07a49184c9a5c5eb0dc2ba579a46c80b3eb6 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Sat, 27 Jan 2024 09:13:28 -0500 Subject: [PATCH] [ruby/prism] Bring back #arg_rest local https://github.com/ruby/prism/commit/9b6907b727 --- lib/prism/debug.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/prism/debug.rb b/lib/prism/debug.rb index f4c0bcf91a..4e8d3f216c 100644 --- a/lib/prism/debug.rb +++ b/lib/prism/debug.rb @@ -59,7 +59,21 @@ module Prism stack = [ISeq.new(RubyVM::InstructionSequence.compile(source).to_a)] while (iseq = stack.pop) - locals << iseq.local_table + names = [*iseq.local_table] + names.map!.with_index do |name, index| + # When an anonymous local variable is present in the iseq's local + # table, it is represented as the stack offset from the top. + # However, when these are dumped to binary and read back in, they + # are replaced with the symbol :#arg_rest. To consistently handle + # this, we replace them here with their index. + if name == :"#arg_rest" + names.length - index + 1 + else + name + end + end + + locals << names iseq.each_child { |child| stack << child } end