[Bug #19973] Warn duplicated keyword arguments after keyword splat
This commit is contained in:
parent
634e0ac140
commit
c8d162c889
9
parse.y
9
parse.y
@ -14551,14 +14551,17 @@ remove_duplicate_keys(struct parser_params *p, NODE *hash)
|
|||||||
NODE *result = 0;
|
NODE *result = 0;
|
||||||
NODE *last_expr = 0;
|
NODE *last_expr = 0;
|
||||||
rb_code_location_t loc = hash->nd_loc;
|
rb_code_location_t loc = hash->nd_loc;
|
||||||
while (hash && RNODE_LIST(hash)->nd_head && RNODE_LIST(hash)->nd_next) {
|
while (hash && RNODE_LIST(hash)->nd_next) {
|
||||||
NODE *head = RNODE_LIST(hash)->nd_head;
|
NODE *head = RNODE_LIST(hash)->nd_head;
|
||||||
NODE *value = RNODE_LIST(hash)->nd_next;
|
NODE *value = RNODE_LIST(hash)->nd_next;
|
||||||
NODE *next = RNODE_LIST(value)->nd_next;
|
NODE *next = RNODE_LIST(value)->nd_next;
|
||||||
st_data_t key = (st_data_t)head;
|
st_data_t key = (st_data_t)head;
|
||||||
st_data_t data;
|
st_data_t data;
|
||||||
RNODE_LIST(value)->nd_next = 0;
|
RNODE_LIST(value)->nd_next = 0;
|
||||||
if (nd_type_p(head, NODE_LIT) &&
|
if (!head) {
|
||||||
|
key = (st_data_t)value;
|
||||||
|
}
|
||||||
|
else if (nd_type_p(head, NODE_LIT) &&
|
||||||
st_delete(literal_keys, (key = (st_data_t)RNODE_LIT(head)->nd_lit, &key), &data)) {
|
st_delete(literal_keys, (key = (st_data_t)RNODE_LIT(head)->nd_lit, &key), &data)) {
|
||||||
NODE *dup_value = (RNODE_LIST((NODE *)data))->nd_next;
|
NODE *dup_value = (RNODE_LIST((NODE *)data))->nd_next;
|
||||||
rb_compile_warn(p->ruby_sourcefile, nd_line((NODE *)data),
|
rb_compile_warn(p->ruby_sourcefile, nd_line((NODE *)data),
|
||||||
@ -14572,7 +14575,7 @@ remove_duplicate_keys(struct parser_params *p, NODE *hash)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
st_insert(literal_keys, (st_data_t)key, (st_data_t)hash);
|
st_insert(literal_keys, (st_data_t)key, (st_data_t)hash);
|
||||||
last_expr = nd_type_p(head, NODE_LIT) ? value : head;
|
last_expr = !head || nd_type_p(head, NODE_LIT) ? value : head;
|
||||||
hash = next;
|
hash = next;
|
||||||
}
|
}
|
||||||
st_foreach(literal_keys, append_literal_keys, (st_data_t)&result);
|
st_foreach(literal_keys, append_literal_keys, (st_data_t)&result);
|
||||||
|
@ -335,6 +335,12 @@ class TestSyntax < Test::Unit::TestCase
|
|||||||
assert_warn(/duplicated/) {r = eval("a.f(**{k: a.add(1), j: a.add(2), k: a.add(3), k: a.add(4)})")}
|
assert_warn(/duplicated/) {r = eval("a.f(**{k: a.add(1), j: a.add(2), k: a.add(3), k: a.add(4)})")}
|
||||||
assert_equal(4, r)
|
assert_equal(4, r)
|
||||||
assert_equal([1, 2, 3, 4], a)
|
assert_equal([1, 2, 3, 4], a)
|
||||||
|
a.clear
|
||||||
|
r = nil
|
||||||
|
z = {}
|
||||||
|
assert_warn(/duplicated/) {r = eval("a.f(k: a.add(1), **z, k: a.add(2))")}
|
||||||
|
assert_equal(2, r)
|
||||||
|
assert_equal([1, 2], a)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_keyword_empty_splat
|
def test_keyword_empty_splat
|
||||||
|
Loading…
x
Reference in New Issue
Block a user