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

ruby-changes:26759

From: marcandre <ko1@a...>
Date: Mon, 14 Jan 2013 17:01:51 +0900 (JST)
Subject: [ruby-changes:26759] marcandRe: r38811 (trunk): * enumerator.c: Require block for Lazy#{take|drop}_while [Bug #7692]

marcandre	2013-01-14 16:42:43 +0900 (Mon, 14 Jan 2013)

  New Revision: 38811

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

  Log:
    * enumerator.c: Require block for Lazy#{take|drop}_while [Bug #7692]

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38810)
+++ ChangeLog	(revision 38811)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jan 14 16:42:28 2013  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* enumerator.c: Require block for Lazy#{take|drop}_while [Bug #7692]
+
 Mon Jan 14 14:41:00 2013  Kenta Murata  <mrkn@m...>
 
 	* ext/bigdecimal/bigdecimal.c (BigDecimal_to_s): use CRuby style.
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 38810)
+++ enumerator.c	(revision 38811)
@@ -1678,6 +1678,9 @@ lazy_take_while_func(VALUE val, VALUE ar https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1678
 static VALUE
 lazy_take_while(VALUE obj)
 {
+    if (!rb_block_given_p()) {
+	rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
+    }
     return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
 					 lazy_take_while_func, 0),
 			   Qnil, 0);
@@ -1745,6 +1748,9 @@ lazy_drop_while(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1748
 {
     NODE *memo;
 
+    if (!rb_block_given_p()) {
+	rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
+    }
     memo = NEW_MEMO(0, 0, FALSE);
     return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj,
 					 lazy_drop_while_func, (VALUE) memo),
Index: test/ruby/test_lazy_enumerator.rb
===================================================================
--- test/ruby/test_lazy_enumerator.rb	(revision 38810)
+++ test/ruby/test_lazy_enumerator.rb	(revision 38811)
@@ -363,4 +363,10 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lazy_enumerator.rb#L363
     assert_ruby_status(["-e", "GC.stress = true", "-e", "(1..10).lazy.map{}.zip(){}"], bug7507)
     assert_ruby_status(["-e", "GC.stress = true", "-e", "(1..10).lazy.map{}.zip().to_a"], bug7507)
   end
+
+  def test_require_block
+    %i[select reject drop_while take_while].each do |method|
+      assert_raise(ArgumentError){ [].lazy.send(method) }
+    end
+  end
 end

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

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