Skip to content

Commit

Permalink
Fix lazy enumerator with index size
Browse files Browse the repository at this point in the history
Fixes [Bug #17889]
  • Loading branch information
jeremyevans committed May 27, 2021
1 parent 029169b commit fd8991f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion enumerator.c
Expand Up @@ -2700,8 +2700,13 @@ lazy_with_index_proc(VALUE proc_entry, struct MEMO* result, VALUE memos, long me
return result;
}

static VALUE
lazy_with_index_size(VALUE proc, VALUE receiver) {
return receiver;
}

static const lazyenum_funcs lazy_with_index_funcs = {
lazy_with_index_proc, 0,
lazy_with_index_proc, lazy_with_index_size,
};

/*
Expand Down
4 changes: 4 additions & 0 deletions test/ruby/test_lazy_enumerator.rb
Expand Up @@ -682,4 +682,8 @@ def test_with_index
ary = (0..Float::INFINITY).lazy.with_index.take(2).to_a
assert_equal([[0, 0], [1, 1]], ary)
end

def test_with_index_size
assert_equal(3, Enumerator::Lazy.new([1, 2, 3], 3){|y, v| y << v}.with_index.size)
end
end

0 comments on commit fd8991f

Please sign in to comment.