diff options
author | John Hawthorn <john@hawthorn.email> | 2022-06-10 09:43:05 -0700 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2022-06-10 14:48:21 -0700 |
commit | 52da90aceefd9f8de06666796f6a2d484ca18036 (patch) | |
tree | 2f09ab04c73ca979dd9561c36e0e51f184fac5af /test/ruby | |
parent | f4747958e546a5d3f2c0033b19c6ad69ce7278b1 (diff) | |
download | ruby-52da90aceefd9f8de06666796f6a2d484ca18036.tar.gz |
Make method id explicit in rb_exec_recursive_outer
Previously, because opt_aref and opt_aset don't push a frame, when they
would call rb_hash to determine the hash value of the key, the initial
level of recursion would incorrectly use the method id at the top of the
stack instead of "hash".
This commit replaces rb_exec_recursive_outer with
rb_exec_recursive_outer_mid, which takes an explicit method id, so that
we can make the hash calculation behave consistently.
rb_exec_recursive_outer was documented as being internal, so I believe
this should be okay to change.
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_hash.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 073a0dabe8..91423f81ea 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -2166,6 +2166,27 @@ class TestHash < Test::Unit::TestCase end end + # Previously this test would fail because rb_hash inside opt_aref would look + # at the current method name + def test_hash_recursion_independent_of_mid + o = Class.new do + def hash(h, k) + h[k] + end + + def any_other_name(h, k) + h[k] + end + end.new + + rec = []; rec << rec + + h = @cls[] + h[rec] = 1 + assert o.hash(h, rec) + assert o.any_other_name(h, rec) + end + def test_any_hash_fixable 20.times do assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") |