[前][次][番号順一覧][スレッド一覧]

ruby-changes:35795

From: nobu <ko1@a...>
Date: Sat, 11 Oct 2014 13:47:01 +0900 (JST)
Subject: [ruby-changes:35795] nobu:r47877 (trunk): parse.y: precedence of duplicated keys

nobu	2014-10-11 13:46:42 +0900 (Sat, 11 Oct 2014)

  New Revision: 47877

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47877

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47876)
+++ ChangeLog	(revision 47877)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Oct 11 13:46:53 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@y...>
 
 	* configure.in (RUBY_NACL): automatically locate pnacl-clang.
Index: parse.y
===================================================================
--- parse.y	(revision 47876)
+++ parse.y	(revision 47877)
@@ -4931,7 +4931,15 @@ assocs		: assoc https://github.com/ruby/ruby/blob/trunk/parse.y#L4931
 		| 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);
 		    %*/
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 47876)
+++ test/ruby/test_syntax.rb	(revision 47877)
@@ -112,6 +112,10 @@ class TestSyntax < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L112
     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}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]