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

ruby-changes:16877

From: nobu <ko1@a...>
Date: Thu, 5 Aug 2010 20:34:45 +0900 (JST)
Subject: [ruby-changes:16877] Ruby:r28873 (trunk): * compile.c (iseq_compile_each): to_a method should be called.

nobu	2010-08-05 20:30:50 +0900 (Thu, 05 Aug 2010)

  New Revision: 28873

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

  Log:
    * compile.c (iseq_compile_each): to_a method should be called.
      [Bug #3658]
    
    * compile.c (iseq_compile_each): ditto for ARGSPUSH.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/test/ruby/test_primitive.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28872)
+++ ChangeLog	(revision 28873)
@@ -1,3 +1,10 @@
+Thu Aug  5 20:30:39 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* compile.c (iseq_compile_each): to_a method should be called.
+	  [Bug #3658]
+
+	* compile.c (iseq_compile_each): ditto for ARGSPUSH.
+
 Thu Aug  5 20:13:49 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* README.EXT, README.EXT.ja (String functions): mention
Index: compile.c
===================================================================
--- compile.c	(revision 28872)
+++ compile.c	(revision 28873)
@@ -4522,14 +4522,23 @@
       }
       case NODE_ARGSCAT:{
 	COMPILE_(ret, "argscat head", node->nd_head, poped);
-	COMPILE_(ret, "argscat body", node->nd_body, poped);
-	if (poped) break;
+	COMPILE(ret, "argscat body", node->nd_body);
+	if (poped) {
+	    ADD_INSN1(ret, nd_line(node), splatarray, Qfalse);
+	    ADD_INSN(ret, nd_line(node), pop);
+	    break;
+	}
 	ADD_INSN(ret, nd_line(node), concatarray);
 	break;
       }
       case NODE_ARGSPUSH:{
-	COMPILE(ret, "arsgpush head", node->nd_head);
+	COMPILE_(ret, "arsgpush head", node->nd_head, poped);
 	COMPILE(ret, "argspush body", node->nd_body);
+	if (poped) {
+	    ADD_INSN1(ret, nd_line(node), splatarray, Qfalse);
+	    ADD_INSN(ret, nd_line(node), pop);
+	    break;
+	}
 	ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
 	ADD_INSN(ret, nd_line(node), concatarray);
 	break;
Index: test/ruby/test_primitive.rb
===================================================================
--- test/ruby/test_primitive.rb	(revision 28872)
+++ test/ruby/test_primitive.rb	(revision 28873)
@@ -405,5 +405,20 @@
     bug3658 = '[ruby-dev:41933]'
     [0, *x=1]
     assert_equal(1, x, bug3658)
+    [0, *x=1, 2]
+    assert_equal(1, x, bug3658)
+    class << (x = Object.new)
+      attr_accessor :to_a_called
+      def to_a
+        @to_a_called = true
+        [self]
+      end
+    end
+    x.to_a_called = false
+    [0, *x]
+    assert(x.to_a_called, bug3658)
+    x.to_a_called = false
+    [0, *x, 2]
+    assert(x.to_a_called, bug3658)
   end
 end

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

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