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

ruby-changes:36960

From: nobu <ko1@a...>
Date: Sun, 28 Dec 2014 13:54:43 +0900 (JST)
Subject: [ruby-changes:36960] nobu:r49041 (trunk): parse.y: fix internal IDs conflict

nobu	2014-12-28 13:54:28 +0900 (Sun, 28 Dec 2014)

  New Revision: 49041

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

  Log:
    parse.y: fix internal IDs conflict
    
    * parse.y (f_kwrest, new_args_tail_gen): unnamed rest keyword and
      keywords bits arguments should be unique.  since internal IDs
      depend on the local variable index in the current scope, new ID
      should be made before popping those vtables.
      [ruby-core:67157] [Bug #10659]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_keyword.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49040)
+++ ChangeLog	(revision 49041)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Dec 28 13:54:26 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (f_kwrest, new_args_tail_gen): unnamed rest keyword and
+	  keywords bits arguments should be unique.  since internal IDs
+	  depend on the local variable index in the current scope, new ID
+	  should be made before popping those vtables.
+	  [ruby-core:67157] [Bug #10659]
+
 Sat Dec 27 20:12:55 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/json/generator/generator.c (JSON_Generator_State_type): add
Index: parse.y
===================================================================
--- parse.y	(revision 49040)
+++ parse.y	(revision 49041)
@@ -4829,6 +4829,7 @@ f_kwrest	: kwrest_mark tIDENTIFIER https://github.com/ruby/ruby/blob/trunk/parse.y#L4829
 		| kwrest_mark
 		    {
 			$$ = internal_id();
+			arg_var($$);
 		    }
 		;
 
@@ -9768,6 +9769,8 @@ new_args_tail_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L9769
 	    kwn = kwn->nd_next;
 	}
 
+	kw_bits = internal_id();
+	if (kr && is_junk_id(kr)) vtable_pop(lvtbl->args, 1);
 	vtable_pop(lvtbl->args, vtable_size(required_kw_vars) + vtable_size(kw_vars) + (b != 0));
 
 	for (i=0; i<vtable_size(required_kw_vars); i++) arg_var(required_kw_vars->tbl[i]);
@@ -9775,7 +9778,6 @@ new_args_tail_gen(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L9778
 	vtable_free(required_kw_vars);
 	vtable_free(kw_vars);
 
-	kw_bits = internal_id();
 	arg_var(kw_bits);
 	if (kr) arg_var(kr);
 	if (b) arg_var(b);
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 49040)
+++ test/ruby/test_keyword.rb	(revision 49041)
@@ -539,4 +539,24 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L539
       o.foo {raise "unreachable"}
     }
   end
+
+  def test_super_with_anon_restkeywords
+    bug10659 = '[ruby-core:67157] [Bug #10659]'
+
+    foo = Class.new do
+      def foo(**h)
+        h
+      end
+    end
+
+    class << (obj = foo.new)
+      def foo(bar: "bar", **)
+        super
+      end
+    end
+
+    assert_nothing_raised(TypeError, bug10659) {
+      assert_equal({:bar => "bar"}, obj.foo, bug10659)
+    }
+  end
 end

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

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