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

ruby-changes:26874

From: marcandre <ko1@a...>
Date: Thu, 24 Jan 2013 16:50:42 +0900 (JST)
Subject: [ruby-changes:26874] marcandRe: r38926 (trunk): * enumerator.c (lazy_zip): raise error for bad arguments

marcandre	2013-01-24 16:50:33 +0900 (Thu, 24 Jan 2013)

  New Revision: 38926

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

  Log:
    * enumerator.c (lazy_zip): raise error for bad arguments
      [Bug #7706]

  Modified files:
    trunk/ChangeLog
    trunk/enumerator.c
    trunk/test/ruby/test_lazy_enumerator.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38925)
+++ ChangeLog	(revision 38926)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan 24 16:47:26 2013  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* enumerator.c (lazy_zip): raise error for bad arguments
+	  [Bug #7706]
+
 Thu Jan 24 16:05:08 2013  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* enumerator.c: Optimize Lazy#zip when passed only arrays
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 38925)
+++ enumerator.c	(revision 38926)
@@ -1663,6 +1663,12 @@ lazy_zip(int argc, VALUE *argv, VALUE ob https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1663
     for (i = 0; i < argc; i++) {
 	v = rb_check_array_type(argv[i]);
 	if (NIL_P(v)) {
+	    for (; i < argc; i++) {
+		if (!rb_respond_to(argv[i], id_each)) {
+		    rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)",
+			rb_obj_classname(argv[i]));
+		}
+	    }
 	    ary = rb_ary_new4(argc, argv);
 	    func = lazy_zip_func;
 	    break;
Index: test/ruby/test_lazy_enumerator.rb
===================================================================
--- test/ruby/test_lazy_enumerator.rb	(revision 38925)
+++ test/ruby/test_lazy_enumerator.rb	(revision 38926)
@@ -213,6 +213,11 @@ class TestLazyEnumerator < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lazy_enumerator.rb#L213
     assert_equal(1, a.current)
   end
 
+  def test_zip_bad_arg
+    a = Step.new(1..3)
+    assert_raise(TypeError){ a.lazy.zip(42) }
+  end
+
   def test_zip_with_block
     # zip should be eager when a block is given
     a = Step.new(1..3)

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

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