[前][次][番号順一覧][スレッド一覧]

ruby-changes:66334

From: Jeremy <ko1@a...>
Date: Fri, 28 May 2021 06:17:56 +0900 (JST)
Subject: [ruby-changes:66334] fd8991f797 (master): Fix lazy enumerator with index size

https://git.ruby-lang.org/ruby.git/commit/?id=fd8991f797

From fd8991f797c145615820b4c76e6b7ac5a71339ea Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Thu, 27 May 2021 13:29:24 -0700
Subject: Fix lazy enumerator with index size

Fixes [Bug #17889]
---
 enumerator.c                      | 7 ++++++-
 test/ruby/test_lazy_enumerator.rb | 4 ++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/enumerator.c b/enumerator.c
index 3ea4330..fac83b4 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -2700,8 +2700,13 @@ lazy_with_index_proc(VALUE proc_entry, struct MEMO* result, VALUE memos, long me https://github.com/ruby/ruby/blob/trunk/enumerator.c#L2700
     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,
 };
 
 /*
diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb
index 3f5a055..2116d0e 100644
--- a/test/ruby/test_lazy_enumerator.rb
+++ b/test/ruby/test_lazy_enumerator.rb
@@ -682,4 +682,8 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lazy_enumerator.rb#L682
     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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]