Dup kwrest hash when merging other keyword arguments [Bug #17481]
This commit is contained in:
parent
cc055d4d3f
commit
c8010fcec0
@ -8157,6 +8157,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
|
|||||||
if (local_body->param.flags.has_kwrest) {
|
if (local_body->param.flags.has_kwrest) {
|
||||||
int idx = local_body->local_table_size - local_kwd->rest_start;
|
int idx = local_body->local_table_size - local_kwd->rest_start;
|
||||||
ADD_GETLOCAL(args, line, idx, lvar_level);
|
ADD_GETLOCAL(args, line, idx, lvar_level);
|
||||||
|
if (local_kwd->num > 0) {
|
||||||
|
ADD_SEND(args, line, rb_intern("dup"), INT2FIX(0));
|
||||||
|
flag |= VM_CALL_KW_SPLAT_MUT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ADD_INSN1(args, line, newhash, INT2FIX(0));
|
ADD_INSN1(args, line, newhash, INT2FIX(0));
|
||||||
|
@ -3681,6 +3681,25 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||||||
assert_equal([42, {:bar=>"x"}], b.new.foo(42), bug8236)
|
assert_equal([42, {:bar=>"x"}], b.new.foo(42), bug8236)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_super_with_keyword_kwrest
|
||||||
|
base = Class.new do
|
||||||
|
def foo(**h)
|
||||||
|
h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
a = Class.new(base) do
|
||||||
|
attr_reader :h
|
||||||
|
def foo(a:, b:, **h)
|
||||||
|
@h = h
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
o = a.new
|
||||||
|
assert_equal({a: 1, b: 2, c: 3}, o.foo(a: 1, b: 2, c: 3))
|
||||||
|
assert_equal({c: 3}, o.h)
|
||||||
|
end
|
||||||
|
|
||||||
def test_zsuper_only_named_kwrest
|
def test_zsuper_only_named_kwrest
|
||||||
bug8416 = '[ruby-core:55033] [Bug #8416]'
|
bug8416 = '[ruby-core:55033] [Bug #8416]'
|
||||||
base = Class.new do
|
base = Class.new do
|
||||||
@ -3689,11 +3708,15 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
a = Class.new(base) do
|
a = Class.new(base) do
|
||||||
|
attr_reader :h
|
||||||
def foo(**h)
|
def foo(**h)
|
||||||
|
@h = h
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_equal({:bar=>"x"}, a.new.foo(bar: "x"), bug8416)
|
o = a.new
|
||||||
|
assert_equal({:bar=>"x"}, o.foo(bar: "x"), bug8416)
|
||||||
|
assert_equal({:bar=>"x"}, o.h)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_zsuper_only_anonymous_kwrest
|
def test_zsuper_only_anonymous_kwrest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user