From 5899f6aa55a02f211545d9cdaef4d86fa0b49528 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 12 Jan 2024 08:58:39 -0800 Subject: Keep hidden local variables when dumping and loading iseqs Fixes [Bug #19975] --- test/ruby/test_iseq.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 9b584c540c..ebb28af116 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -566,6 +566,23 @@ class TestISeq < Test::Unit::TestCase iseq2 end + def test_to_binary_with_hidden_local_variables + assert_iseq_to_binary("for foo in bar; end") + + bin = RubyVM::InstructionSequence.compile(<<-RUBY).to_binary + Object.new.instance_eval do + a = [] + def self.bar; [1] end + for foo in bar + a << (foo * 2) + end + a + end + RUBY + v = RubyVM::InstructionSequence.load_from_binary(bin).eval + assert_equal([2], v) + end + def test_to_binary_with_objects assert_iseq_to_binary("[]"+100.times.map{|i|"<