mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix code locations of array node inside hash node when multiple kw splats
This is broken at least since 2.5 (I didn't check earlier versions). It resulted in failure in test_ast.rb when the tests were added before the parser change. Basically, in remove_duplicate_keys, if the node is modified, set the location information to the previous location information. The removal of keys should not affect the location in the code.
This commit is contained in:
parent
1d5066efb0
commit
c6464c44c0
Notes:
git
2019-09-06 01:58:16 +09:00
2 changed files with 9 additions and 0 deletions
2
parse.y
2
parse.y
|
@ -11336,6 +11336,7 @@ remove_duplicate_keys(struct parser_params *p, NODE *hash)
|
|||
{
|
||||
st_table *literal_keys = st_init_numtable_with_size(hash->nd_alen / 2);
|
||||
NODE *result = 0;
|
||||
rb_code_location_t loc = hash->nd_loc;
|
||||
while (hash && hash->nd_head && hash->nd_next) {
|
||||
NODE *head = hash->nd_head;
|
||||
NODE *value = hash->nd_next;
|
||||
|
@ -11361,6 +11362,7 @@ remove_duplicate_keys(struct parser_params *p, NODE *hash)
|
|||
if (!result) result = hash;
|
||||
else list_concat(result, hash);
|
||||
}
|
||||
result->nd_loc = loc;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,13 @@ class TestSyntax < Test::Unit::TestCase
|
|||
assert_equal([kw], [kw, **kw, **kw])
|
||||
assert_equal([h], [h, **kw, **kw])
|
||||
assert_equal([h, h], [h, **kw, **kw, **h])
|
||||
|
||||
assert_equal([h, {:a=>2}], [h, **{}, **h, a: 2])
|
||||
assert_equal([h, h], [h, **{}, a: 2, **h])
|
||||
assert_equal([h, h], [h, a: 2, **{}, **h])
|
||||
assert_equal([h, h], [h, a: 2, **h, **{}])
|
||||
assert_equal([h, {:a=>2}], [h, **h, a: 2, **{}])
|
||||
assert_equal([h, {:a=>2}], [h, **h, **{}, a: 2])
|
||||
end
|
||||
|
||||
def test_normal_argument
|
||||
|
|
Loading…
Reference in a new issue