mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix keyword argument separation warning when using send
vm_call_opt_send was dropping VM_CALL_KW_SPLAT, so this just makes it not drop it, to get the same behavior as calling the method directly.
This commit is contained in:
parent
e13c0bb820
commit
d646a292cd
2 changed files with 70 additions and 2 deletions
|
@ -365,6 +365,74 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||
assert_equal([1, h3], c.method(:m)[**h3])
|
||||
end
|
||||
|
||||
def test_send_kwsplat
|
||||
kw = {}
|
||||
h = {'a'=>1}
|
||||
h2 = {'a'=>1}
|
||||
h3 = {'a'=>1, :a=>1}
|
||||
|
||||
c = Object.new
|
||||
def c.m(*args)
|
||||
args
|
||||
end
|
||||
assert_equal([], c.send(:m, **{}))
|
||||
assert_equal([], c.send(:m, **kw))
|
||||
assert_equal([h], c.send(:m, **h))
|
||||
assert_equal([h2], c.send(:m, **h2))
|
||||
assert_equal([h3], c.send(:m, **h3))
|
||||
|
||||
def c.m; end
|
||||
assert_nil(c.send(:m, **{}))
|
||||
assert_nil(c.send(:m, **kw))
|
||||
assert_raise(ArgumentError) { c.send(:m, **h) }
|
||||
assert_raise(ArgumentError) { c.send(:m, **h2) }
|
||||
assert_raise(ArgumentError) { c.send(:m, **h3) }
|
||||
|
||||
def c.m(args)
|
||||
args
|
||||
end
|
||||
assert_raise(ArgumentError) { c.send(:m, **{}) }
|
||||
assert_raise(ArgumentError) { c.send(:m, **kw) }
|
||||
assert_equal(h, c.send(:m, **h))
|
||||
assert_equal(h2, c.send(:m, **h2))
|
||||
assert_equal(h3, c.send(:m, **h3))
|
||||
|
||||
def c.m(**args)
|
||||
args
|
||||
end
|
||||
assert_equal(kw, c.send(:m, **{}))
|
||||
assert_equal(kw, c.send(:m, **kw))
|
||||
assert_equal(h, c.send(:m, **h))
|
||||
assert_equal(h2, c.send(:m, **h2))
|
||||
assert_equal(h3, c.send(:m, **h3))
|
||||
|
||||
def c.m(arg, **args)
|
||||
[arg, args]
|
||||
end
|
||||
assert_raise(ArgumentError) { c.send(:m, **{}) }
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do
|
||||
assert_equal([kw, kw], c.send(:m, **kw))
|
||||
end
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do
|
||||
assert_equal([h, kw], c.send(:m, **h))
|
||||
end
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do
|
||||
assert_equal([h2, kw], c.send(:m, **h2))
|
||||
end
|
||||
assert_warn(/The keyword argument is passed as the last hash parameter.* for `m'/m) do
|
||||
assert_equal([h3, kw], c.send(:m, **h3))
|
||||
end
|
||||
|
||||
def c.m(arg=1, **args)
|
||||
[arg=1, args]
|
||||
end
|
||||
assert_equal([1, kw], c.send(:m, **{}))
|
||||
assert_equal([1, kw], c.send(:m, **kw))
|
||||
assert_equal([1, h], c.send(:m, **h))
|
||||
assert_equal([1, h2], c.send(:m, **h2))
|
||||
assert_equal([1, h3], c.send(:m, **h3))
|
||||
end
|
||||
|
||||
def p1
|
||||
Proc.new do |str: "foo", num: 424242|
|
||||
[str, num]
|
||||
|
|
|
@ -2310,8 +2310,8 @@ vm_call_opt_send(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct
|
|||
ci = &ci_entry.ci;
|
||||
ci_entry.ci = *orig_ci;
|
||||
}
|
||||
unsigned int kw_splat = 0;
|
||||
if (ci->flag & VM_CALL_KWARG) {
|
||||
unsigned int kw_splat = ci->flag & VM_CALL_KW_SPLAT;
|
||||
if (!kw_splat && (ci->flag & VM_CALL_KWARG)) {
|
||||
/* TODO: delegate kw_arg without making a Hash object */
|
||||
ci->flag = ci->flag & ~VM_CALL_KWARG;
|
||||
kw_splat = VM_CALL_KW_SPLAT;
|
||||
|
|
Loading…
Reference in a new issue