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