diff options
-rw-r--r-- | enumerator.c | 14 | ||||
-rw-r--r-- | test/ruby/test_lazy_enumerator.rb | 7 |
2 files changed, 12 insertions, 9 deletions
diff --git a/enumerator.c b/enumerator.c index 1522a3f699..769d940dab 100644 --- a/enumerator.c +++ b/enumerator.c @@ -1754,12 +1754,11 @@ lazy_drop(VALUE obj, VALUE n) static VALUE lazy_drop_while_func(VALUE val, VALUE args, int argc, VALUE *argv) { - NODE *memo = RNODE(args); - - if (!memo->u3.state && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) { - memo->u3.state = TRUE; + VALUE memo = rb_ivar_get(argv[0], id_memo); + if (NIL_P(memo) && !RTEST(rb_yield_values2(argc - 1, &argv[1]))) { + rb_ivar_set(argv[0], id_memo, memo = Qtrue); } - if (memo->u3.state) { + if (memo == Qtrue) { rb_funcall2(argv[0], id_yield, argc - 1, argv + 1); } return Qnil; @@ -1768,14 +1767,11 @@ lazy_drop_while_func(VALUE val, VALUE args, int argc, VALUE *argv) static VALUE 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), + lazy_drop_while_func, 0), Qnil, 0); } diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 35e92c9050..a7c5a4a947 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -250,6 +250,13 @@ class TestLazyEnumerator < Test::Unit::TestCase assert_equal([*(1..5)]*5, take5.flat_map{take5}.force, bug7696) end + def test_drop_while_nested + bug7696 = '[ruby-core:51470]' + a = Step.new(1..10) + drop5 = a.lazy.drop_while{|x| x < 6} + assert_equal([*(6..10)]*5, drop5.flat_map{drop5}.force, bug7696) + end + def test_take_rewound bug7696 = '[ruby-core:51470]' e=(1..42).lazy.take(2) |