summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-11-17 14:05:37 -0500
committerPeter Zhu <peter@peterzhu.ca>2023-11-17 13:08:43 -0800
commit3dd77bc056de19a1cc0ad3fafdb8e49c429dec5a (patch)
treebc18b727a2a043d17dc66ffeec1352232bd37745 /test/ruby
parent7c99e43c3f050244b06dbd18de4f605ea70d234c (diff)
Fix corruption when out of shape during ivar remove
Reproduction script: ``` o = Object.new 10.times { |i| o.instance_variable_set(:"@a#{i}", i) } i = 0 a = Object.new while RubyVM::Shape.shapes_available > 2 a.instance_variable_set(:"@i#{i}", 1) i += 1 end o.remove_instance_variable(:@a0) puts o.instance_variable_get(:@a1) ``` Before this patch, it would incorrectly output `2` and now it correctly outputs `1`.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_shapes.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb
index 9f455e4389..f985f8c611 100644
--- a/test/ruby/test_shapes.rb
+++ b/test/ruby/test_shapes.rb
@@ -414,6 +414,27 @@ class TestShapes < Test::Unit::TestCase
assert_equal true, A.instance_variable_defined?(:@a)
end;
end
+
+ def test_run_out_of_shape_during_remove_instance_variable
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ o = Object.new
+ 10.times { |i| o.instance_variable_set(:"@a#{i}", i) }
+
+ i = 0
+ a = Object.new
+ while RubyVM::Shape.shapes_available > 2
+ a.instance_variable_set(:"@i#{i}", 1)
+ i += 1
+ end
+
+ o.remove_instance_variable(:@a0)
+ (1...10).each do |i|
+ assert_equal(i, o.instance_variable_get(:"@a#{i}"))
+ end
+ end;
+ end
+
def test_run_out_of_shape_remove_instance_variable
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;