diff options
-rw-r--r-- | enumerator.c | 4 | ||||
-rw-r--r-- | test/ruby/test_lazy_enumerator.rb | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/enumerator.c b/enumerator.c index 9de08d7d2a..a996566b7b 100644 --- a/enumerator.c +++ b/enumerator.c @@ -1448,6 +1448,8 @@ lazy_init_block_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, m)) #define LAZY_MEMO_PACKED_P(memo) ((memo)->memo_flags & LAZY_MEMO_PACKED) #define LAZY_MEMO_SET_BREAK(memo) ((memo)->memo_flags |= LAZY_MEMO_BREAK) #define LAZY_MEMO_SET_VALUE(memo, value) MEMO_V2_SET(memo, value) +#define LAZY_MEMO_SET_PACKED(memo) ((memo)->memo_flags |= LAZY_MEMO_PACKED) +#define LAZY_MEMO_RESET_PACKED(memo) ((memo)->memo_flags &= ~LAZY_MEMO_PACKED) static VALUE lazy_init_yielder(VALUE val, VALUE m, int argc, VALUE *argv) @@ -1743,6 +1745,7 @@ lazy_map_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo_inde { VALUE value = lazyenum_yield_values(proc_entry, result); LAZY_MEMO_SET_VALUE(result, value); + LAZY_MEMO_RESET_PACKED(result); return result; } @@ -1913,6 +1916,7 @@ lazy_grep_iter_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long mem if (!RTEST(chain)) return 0; value = rb_proc_call_with_block(entry->proc, 1, &(result->memo_value), Qnil); LAZY_MEMO_SET_VALUE(result, value); + LAZY_MEMO_RESET_PACKED(result); return result; } diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb index 792a95bb7e..e6888583f9 100644 --- a/test/ruby/test_lazy_enumerator.rb +++ b/test/ruby/test_lazy_enumerator.rb @@ -14,7 +14,14 @@ class TestLazyEnumerator < Test::Unit::TestCase def each(*args) @args = args - @enum.each {|i| @current = i; yield i} + @enum.each do |v| + @current = v + if v.is_a? Enumerable + yield *v + else + yield v + end + end end end @@ -100,6 +107,15 @@ class TestLazyEnumerator < Test::Unit::TestCase assert_equal(1, a.current) end + def test_map_packed_nested + bug = '[ruby-core:81638] [Bug#13648]' + + a = Step.new([[1, 2]]) + expected = [[[1, 2]]] + assert_equal(expected, a.map {|*args| args}.map {|*args| args}.to_a) + assert_equal(expected, a.lazy.map {|*args| args}.map {|*args| args}.to_a, bug) + end + def test_flat_map a = Step.new(1..3) assert_equal(2, a.flat_map {|x| [x * 2]}.first) |