ruby-changes:59057
From: Jeremy <ko1@a...>
Date: Wed, 4 Dec 2019 06:18:49 +0900 (JST)
Subject: [ruby-changes:59057] a029b54ec7 (master): Make Enumerator::Chain#each treat lambdas as lambda
https://git.ruby-lang.org/ruby.git/commit/?id=a029b54ec7 From a029b54ec716812ade37fef1f857c49f821a8cc8 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Wed, 28 Aug 2019 16:41:39 -0700 Subject: Make Enumerator::Chain#each treat lambdas as lambda Previously, lambdas were converted to procs because of how rb_block_call works. Switch to rb_funcall_with_block, which handles procs as procs and lambdas as lambdas. Fixes [Bug #15613] diff --git a/enumerator.c b/enumerator.c index a5d7106..67b9302 100644 --- a/enumerator.c +++ b/enumerator.c @@ -3112,12 +3112,6 @@ enum_chain_enum_size(VALUE obj, VALUE args, VALUE eobj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L3112 } static VALUE -enum_chain_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(_, block)) -{ - return rb_funcallv(block, id_call, argc, argv); -} - -static VALUE enum_chain_enum_no_size(VALUE obj, VALUE args, VALUE eobj) { return Qnil; @@ -3148,10 +3142,9 @@ enum_chain_each(int argc, VALUE *argv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L3142 enums = objptr->enums; block = rb_block_proc(); - for (i = 0; i < RARRAY_LEN(enums); i++) { objptr->pos = i; - rb_block_call(RARRAY_AREF(enums, i), id_each, argc, argv, enum_chain_yield_block, block); + rb_funcall_with_block(RARRAY_AREF(enums, i), id_each, argc, argv, block); } return obj; diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 65adb5a..75cf1ae 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -864,4 +864,20 @@ class TestEnumerator < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enumerator.rb#L864 ], enum.to_a } end + + def test_chain_each_lambda + c = Class.new do + include Enumerable + attr_reader :is_lambda + def each(&block) + return to_enum unless block + @is_lambda = block.lambda? + end + end + e = c.new + e.chain.each{} + assert_equal(false, e.is_lambda) + e.chain.each(&->{}) + assert_equal(true, e.is_lambda) + end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/