1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Convert empty keyword hash to required positional argument and warn for method_missing

This is the same as the bmethod, sym proc, and send cases,
where we don't remove the keyword splat, so later code can
move it to a required positional parameter and warn.
This commit is contained in:
Jeremy Evans 2019-09-05 13:07:28 -07:00
parent e220b467ef
commit 729de9ee68
2 changed files with 13 additions and 5 deletions

View file

@ -728,8 +728,12 @@ class TestKeywordArguments < Test::Unit::TestCase
def c.method_missing(_, args)
args
end
assert_raise(ArgumentError) { c.m(**{}) }
assert_raise(ArgumentError) { c.m(**kw) }
assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do
assert_equal(kw, c.m(**{}))
end
assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do
assert_equal(kw, c.m(**kw))
end
assert_equal(h, c.m(**h))
assert_equal(h, c.m(a: 1))
assert_equal(h2, c.m(**h2))
@ -751,8 +755,12 @@ class TestKeywordArguments < Test::Unit::TestCase
def c.method_missing(_, arg, **args)
[arg, args]
end
assert_raise(ArgumentError) { c.m(**{}) }
assert_raise(ArgumentError) { c.m(**kw) }
assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do
assert_equal([kw, kw], c.m(**{}))
end
assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do
assert_equal([kw, kw], c.m(**kw))
end
assert_warn(/The keyword argument is passed as the last hash parameter.* for `method_missing'/m) do
assert_equal([h, kw], c.m(**h))
end

View file

@ -2429,7 +2429,7 @@ vm_call_method_missing(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
struct rb_call_cache cc_entry, *cc;
unsigned int argc;
CALLER_SETUP_ARG(reg_cfp, calling, orig_ci);
CALLER_SETUP_ARG_WITHOUT_KW_SPLAT(reg_cfp, calling, orig_ci);
argc = calling->argc+1;
ci_entry.flag = VM_CALL_FCALL | VM_CALL_OPT_SEND | (calling->kw_splat ? VM_CALL_KW_SPLAT : 0);