diff options
| author | nagachika <nagachika@ruby-lang.org> | 2024-11-10 12:31:36 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2024-11-10 12:55:34 +0900 |
| commit | 288e24b73ab20100b63ae7d30fb06a7d8a19de6e (patch) | |
| tree | fec6b18b2dc2843d1f8ed130ddfc7a00e85c2e97 /test | |
| parent | 31b58f89c682e2568c1d7b3299a13a64fbc846de (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')
| -rw-r--r-- | test/ruby/test_proc.rb | 18 |
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}) |
