From 8ca504214d8a20bdda05b65016812fa7234faad4 Mon Sep 17 00:00:00 2001 From: marcandre Date: Mon, 14 Jan 2013 07:42:43 +0000 Subject: * enumerator.c: Require block for Lazy#{take|drop}_while [Bug #7692] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38811 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ enumerator.c | 6 ++++++ test/ruby/test_lazy_enumerator.rb | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7866c86da3..d9b59ced07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Jan 14 16:42:28 2013 Marc-Andre Lafortune + + * enumerator.c: Require block for Lazy#{take|drop}_while [Bug #7692] + Mon Jan 14 14:41:00 2013 Kenta Murata * ext/bigdecimal/bigdecimal.c (BigDecimal_to_s): use CRuby style. diff --git a/enumerator.c b/enumerator.c index d488093ce8..7a7cc1de83 100644 --- a/enumerator.c +++ b/enumerator.c @@ -1678,6 +1678,9 @@ lazy_take_while_func(VALUE val, VALUE args, int argc, VALUE *argv) 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) { 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), diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 7576c942a5..30677291f4 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -363,4 +363,10 @@ EOS 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 -- cgit v1.2.3