From f788ff35567206dad1d29117bb3b163e4ac6da92 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 15 Dec 2023 11:21:39 +0900 Subject: [PATCH] add a test proposed at https://bugs.ruby-lang.org/issues/20050#note-5 --- test/ruby/test_hash.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 639707d8eb66a4..455521105e2ba4 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -2303,4 +2303,26 @@ def test_compare_by_identity_during_iteration end end end + + def test_ar_hash_to_st_hash + assert_normal_exit("#{<<~"begin;"}\n#{<<~'end;'}", 'https://bugs.ruby-lang.org/issues/20050#note-5') + begin; + srand(0) + class Foo + def to_a + [] + end + + def hash + $h.delete($h.keys.sample) if rand < 0.1 + to_a.hash + end + end + + 1000.times do + $h = {} + (0..10).each {|i| $h[Foo.new] ||= {} } + end + end; + end end