summaryrefslogtreecommitdiff
path: root/test/ruby/test_proc.rb
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2024-11-10 12:31:36 +0900
committernagachika <nagachika@ruby-lang.org>2024-11-10 12:55:34 +0900
commit288e24b73ab20100b63ae7d30fb06a7d8a19de6e (patch)
treefec6b18b2dc2843d1f8ed130ddfc7a00e85c2e97 /test/ruby/test_proc.rb
parent31b58f89c682e2568c1d7b3299a13a64fbc846de (diff)
merge revision(s) 29c480dd6fca993590c82078ba797e2c4e876ac7: [Backport #20853]
[Bug #20853] Fix Proc#hash to not change after compaction The hash value of a Proc must remain constant after a compaction, otherwise it may not work as the key in a hash table.
Diffstat (limited to 'test/ruby/test_proc.rb')
-rw-r--r--test/ruby/test_proc.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 2b3590d4d0..35455ecd5e 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -168,6 +168,24 @@ class TestProc < Test::Unit::TestCase
assert_operator(procs.map(&:hash).uniq.size, :>=, 500)
end
+ def test_hash_does_not_change_after_compaction
+ # [Bug #20853]
+ [
+ "proc {}", # iseq backed proc
+ "{}.to_proc", # ifunc backed proc
+ ":hello.to_proc", # symbol backed proc
+ ].each do |proc|
+ assert_separately([], <<~RUBY)
+ p1 = #{proc}
+ hash = p1.hash
+
+ GC.verify_compaction_references(expand_heap: true, toward: :empty)
+
+ assert_equal(hash, p1.hash, "proc is `#{proc}`")
+ RUBY
+ end
+ end
+
def test_block_par
assert_equal(10, Proc.new{|&b| b.call(10)}.call {|x| x})
assert_equal(12, Proc.new{|a,&b| b.call(a)}.call(12) {|x| x})