Skip to content

Commit a029b54

Browse files
committed
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 ruby#15613]
1 parent 47c97e1 commit a029b54

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

enumerator.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,12 +3111,6 @@ enum_chain_enum_size(VALUE obj, VALUE args, VALUE eobj)
31113111
return enum_chain_size(obj);
31123112
}
31133113

3114-
static VALUE
3115-
enum_chain_yield_block(RB_BLOCK_CALL_FUNC_ARGLIST(_, block))
3116-
{
3117-
return rb_funcallv(block, id_call, argc, argv);
3118-
}
3119-
31203114
static VALUE
31213115
enum_chain_enum_no_size(VALUE obj, VALUE args, VALUE eobj)
31223116
{
@@ -3148,10 +3142,9 @@ enum_chain_each(int argc, VALUE *argv, VALUE obj)
31483142
enums = objptr->enums;
31493143
block = rb_block_proc();
31503144

3151-
31523145
for (i = 0; i < RARRAY_LEN(enums); i++) {
31533146
objptr->pos = i;
3154-
rb_block_call(RARRAY_AREF(enums, i), id_each, argc, argv, enum_chain_yield_block, block);
3147+
rb_funcall_with_block(RARRAY_AREF(enums, i), id_each, argc, argv, block);
31553148
}
31563149

31573150
return obj;

test/ruby/test_enumerator.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,4 +864,20 @@ def test_produce
864864
], enum.to_a
865865
}
866866
end
867+
868+
def test_chain_each_lambda
869+
c = Class.new do
870+
include Enumerable
871+
attr_reader :is_lambda
872+
def each(&block)
873+
return to_enum unless block
874+
@is_lambda = block.lambda?
875+
end
876+
end
877+
e = c.new
878+
e.chain.each{}
879+
assert_equal(false, e.is_lambda)
880+
e.chain.each(&->{})
881+
assert_equal(true, e.is_lambda)
882+
end
867883
end

0 commit comments

Comments
 (0)