Skip to content

Commit

Permalink
Do not modify provided argument splat when using ruby2_keywords with …
Browse files Browse the repository at this point in the history
…anonymous splat

Previously, this would push the provided keywords onto the argument
splat.  Add ruby2_keywords to the list of other checks for whether
it is safe for treating a given splat as mutable when the called
method accepts an anonymous splat.
  • Loading branch information
jeremyevans committed Jan 31, 2024
1 parent 71f16d4 commit c469799
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/ruby/test_keyword.rb
Expand Up @@ -2809,6 +2809,24 @@ class << o
assert_raise(FrozenError) { c.send(:ruby2_keywords, :baz) }
end

def test_anon_splat_ruby2_keywords
singleton_class.class_exec do
def bar(*a, **kw)
[a, kw]
end

ruby2_keywords def bar_anon(*)
bar(*)
end
end

a = [1, 2]
kw = {a: 1}
assert_equal([[1, 2], {a: 1}], bar_anon(*a, **kw))
assert_equal([1, 2], a)
assert_equal({a: 1}, kw)
end

def test_top_ruby2_keywords
assert_in_out_err([], <<-INPUT, ["[1, 2, 3]", "{:k=>1}"], [])
def bar(*a, **kw)
Expand Down
1 change: 1 addition & 0 deletions vm_args.c
Expand Up @@ -518,6 +518,7 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
given_argc == ISEQ_BODY(iseq)->param.lead_num + (kw_flag ? 2 : 1) &&
!ISEQ_BODY(iseq)->param.flags.has_opt &&
!ISEQ_BODY(iseq)->param.flags.has_post &&
!ISEQ_BODY(iseq)->param.flags.ruby2_keywords &&
(!kw_flag ||
!ISEQ_BODY(iseq)->param.flags.has_kw ||
!ISEQ_BODY(iseq)->param.flags.has_kwrest ||
Expand Down

0 comments on commit c469799

Please sign in to comment.