Ensure keyword splat method argument is hash

Commit e87d088291 introduced a
regression where the keyword splat object passed by the caller
would be directly used by callee as keyword splat parameters,
if it implemented #to_hash.  The return value of #to_hash would be
ignored in this case.
This commit is contained in:
Jeremy Evans 2023-10-30 11:52:02 -07:00
Родитель c56dd94db0
Коммит ae48d4ad2e
2 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -132,6 +132,15 @@ class TestCall < Test::Unit::TestCase
assert_equal([0, 1, 2, b], aaa(0, *ary, &ary.pop), bug16504) assert_equal([0, 1, 2, b], aaa(0, *ary, &ary.pop), bug16504)
end end
def test_call_args_splat_with_nonhash_keyword_splat
o = Object.new
def o.to_hash; {a: 1} end
def self.f(*a, **kw)
kw
end
assert_equal Hash, f(*[], **o).class
end
OVER_STACK_LEN = (ENV['RUBY_OVER_STACK_LEN'] || 150).to_i # Greater than VM_ARGC_STACK_MAX OVER_STACK_LEN = (ENV['RUBY_OVER_STACK_LEN'] || 150).to_i # Greater than VM_ARGC_STACK_MAX
OVER_STACK_ARGV = OVER_STACK_LEN.times.to_a.freeze OVER_STACK_ARGV = OVER_STACK_LEN.times.to_a.freeze

Просмотреть файл

@ -549,6 +549,8 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag); converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
rb_ary_push(args->rest, converted_keyword_hash); rb_ary_push(args->rest, converted_keyword_hash);
keyword_hash = Qnil; keyword_hash = Qnil;
} else {
keyword_hash = converted_keyword_hash;
} }
int len = RARRAY_LENINT(args->rest); int len = RARRAY_LENINT(args->rest);