[Bug #22496] Make lazy each_with_index call super

`Lasy::Enumerator#each_with_index` should not be lazy when the block
is given.  Fix up for [Bug #21142].
This commit is contained in:
Nobuyoshi Nakada 2026-11-03 09:05:28 +09:00
parent 64d821e685
commit 90dbced795
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2026-11-03 03:34:21 +00:00
2 changed files with 7 additions and 0 deletions

View File

@ -2770,6 +2770,9 @@ lazy_with_index_from(VALUE obj, VALUE memo)
static VALUE
lazy_each_with_index(VALUE obj)
{
if (rb_block_given_p()) {
return rb_call_super(0, 0);
}
return lazy_with_index_from(obj, LONG2NUM(0));
}

View File

@ -765,6 +765,10 @@ EOS
ary = 100.times.lazy.take(0).each_with_index.to_a
assert_equal([], ary)
ary = []
3.times.lazy.each_with_index { |*a| ary << a }
assert_equal([[0, 0], [1, 1], [2, 2]], ary)
end
def test_with_index_size