mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: precedence of duplicated keys
* parse.y (assocs): concatenate splatted literal hashes. the former key has precedence even if duplicated literal keys follow. [ruby-core:65368] [Bug #10315] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
81ce0e3853
commit
1571682719
3 changed files with 19 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
Sat Oct 11 13:46:53 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (assocs): concatenate splatted literal hashes. the
|
||||
former key has precedence even if duplicated literal keys
|
||||
follow. [ruby-core:65368] [Bug #10315]
|
||||
|
||||
Sat Oct 11 12:27:03 2014 Yuki Yugui Sonoda <yugui@yugui.jp>
|
||||
|
||||
* configure.in (RUBY_NACL): automatically locate pnacl-clang.
|
||||
|
|
10
parse.y
10
parse.y
|
@ -4931,7 +4931,15 @@ assocs : assoc
|
|||
| assocs ',' assoc
|
||||
{
|
||||
/*%%%*/
|
||||
$$ = list_concat($1, $3);
|
||||
NODE *assocs = $1;
|
||||
NODE *tail = $3;
|
||||
if (assocs->nd_head &&
|
||||
!tail->nd_head && nd_type(tail->nd_next) == NODE_ARRAY &&
|
||||
nd_type(tail->nd_next->nd_head) == NODE_HASH) {
|
||||
/* DSTAR */
|
||||
tail = tail->nd_next->nd_head->nd_head;
|
||||
}
|
||||
$$ = list_concat(assocs, tail);
|
||||
/*%
|
||||
$$ = rb_ary_push($1, $3);
|
||||
%*/
|
||||
|
|
|
@ -112,6 +112,10 @@ class TestSyntax < Test::Unit::TestCase
|
|||
assert_equal([11, 22], o.kw(k2: 22, **h))
|
||||
assert_equal([11, 12], o.kw(**h, **{k2: 22}))
|
||||
assert_equal([11, 22], o.kw(**{k2: 22}, **h))
|
||||
|
||||
bug10315 = '[ruby-core:65368] [Bug #10315]'
|
||||
assert_equal([22, 2], o.kw(**{k1: 22}, **{k1: 23}), bug10315)
|
||||
|
||||
h = {k3: 31}
|
||||
assert_raise(ArgumentError) {o.kw(**h)}
|
||||
h = {"k1"=>11, k2: 12}
|
||||
|
|
Loading…
Reference in a new issue