diff options
author | Peter Zhu <[email protected]> | 2024-10-30 16:41:55 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2024-11-01 10:49:50 -0400 |
commit | 29c480dd6fca993590c82078ba797e2c4e876ac7 (patch) | |
tree | b2a488f417fb6ebd6111c0965e3ef1e1683da427 /test/ruby | |
parent | 40cd292f9573b763074f08dea451144c3aaf19c6 (diff) |
[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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11966
Diffstat (limited to 'test/ruby')
-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 fcf00776a6..6f100c225f 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}) |