Add back checks for empty kw splat with tests (#4405)
This reverts commit a224ce8150f2bc687cf79eb415c931d87a4cd247. Turns out the checks are needed to handle splatting an array with an empty ruby2 keywords hash.
This commit is contained in:
parent
1f2b5c6dfe
commit
dee58d7ae7
Notes:
git
2021-04-24 11:17:41 +09:00
Merged-By: XrXr
@ -2411,6 +2411,13 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||||||
args
|
args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def empty_method
|
||||||
|
end
|
||||||
|
|
||||||
|
def opt(arg = :opt)
|
||||||
|
arg
|
||||||
|
end
|
||||||
|
|
||||||
ruby2_keywords def foo_dbar(*args)
|
ruby2_keywords def foo_dbar(*args)
|
||||||
dbar(*args)
|
dbar(*args)
|
||||||
end
|
end
|
||||||
@ -2419,6 +2426,16 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||||||
dbaz(*args)
|
dbaz(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ruby2_keywords def clear_last_empty_method(*args)
|
||||||
|
args.last.clear
|
||||||
|
empty_method(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
ruby2_keywords def clear_last_opt(*args)
|
||||||
|
args.last.clear
|
||||||
|
opt(*args)
|
||||||
|
end
|
||||||
|
|
||||||
define_method(:dbar) do |*args, **kw|
|
define_method(:dbar) do |*args, **kw|
|
||||||
[args, kw]
|
[args, kw]
|
||||||
end
|
end
|
||||||
@ -2653,6 +2670,9 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||||||
assert_equal([[1, h1], {}], o.foo(:pass_bar, 1, :a=>1))
|
assert_equal([[1, h1], {}], o.foo(:pass_bar, 1, :a=>1))
|
||||||
assert_equal([[1, h1], {}], o.foo(:pass_cfunc, 1, :a=>1))
|
assert_equal([[1, h1], {}], o.foo(:pass_cfunc, 1, :a=>1))
|
||||||
|
|
||||||
|
assert_equal(:opt, o.clear_last_opt(a: 1))
|
||||||
|
assert_nothing_raised(ArgumentError) { o.clear_last_empty_method(a: 1) }
|
||||||
|
|
||||||
assert_warn(/Skipping set of ruby2_keywords flag for bar \(method accepts keywords or method does not accept argument splat\)/) do
|
assert_warn(/Skipping set of ruby2_keywords flag for bar \(method accepts keywords or method does not accept argument splat\)/) do
|
||||||
assert_nil(c.send(:ruby2_keywords, :bar))
|
assert_nil(c.send(:ruby2_keywords, :bar))
|
||||||
end
|
end
|
||||||
|
@ -2412,6 +2412,7 @@ vm_callee_setup_arg(rb_execution_context_t *ec, struct rb_calling_info *calling,
|
|||||||
if (LIKELY(rb_simple_iseq_p(iseq))) {
|
if (LIKELY(rb_simple_iseq_p(iseq))) {
|
||||||
rb_control_frame_t *cfp = ec->cfp;
|
rb_control_frame_t *cfp = ec->cfp;
|
||||||
CALLER_SETUP_ARG(cfp, calling, ci);
|
CALLER_SETUP_ARG(cfp, calling, ci);
|
||||||
|
CALLER_REMOVE_EMPTY_KW_SPLAT(cfp, calling, ci);
|
||||||
|
|
||||||
if (calling->argc != iseq->body->param.lead_num) {
|
if (calling->argc != iseq->body->param.lead_num) {
|
||||||
argument_arity_error(ec, iseq, calling->argc, iseq->body->param.lead_num, iseq->body->param.lead_num);
|
argument_arity_error(ec, iseq, calling->argc, iseq->body->param.lead_num, iseq->body->param.lead_num);
|
||||||
@ -2425,6 +2426,7 @@ vm_callee_setup_arg(rb_execution_context_t *ec, struct rb_calling_info *calling,
|
|||||||
else if (rb_iseq_only_optparam_p(iseq)) {
|
else if (rb_iseq_only_optparam_p(iseq)) {
|
||||||
rb_control_frame_t *cfp = ec->cfp;
|
rb_control_frame_t *cfp = ec->cfp;
|
||||||
CALLER_SETUP_ARG(cfp, calling, ci);
|
CALLER_SETUP_ARG(cfp, calling, ci);
|
||||||
|
CALLER_REMOVE_EMPTY_KW_SPLAT(cfp, calling, ci);
|
||||||
|
|
||||||
const int lead_num = iseq->body->param.lead_num;
|
const int lead_num = iseq->body->param.lead_num;
|
||||||
const int opt_num = iseq->body->param.opt_num;
|
const int opt_num = iseq->body->param.opt_num;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user