From 52da90aceefd9f8de06666796f6a2d484ca18036 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 10 Jun 2022 09:43:05 -0700 Subject: 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. --- test/ruby/test_hash.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby') 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;'}") -- cgit v1.2.3