Bug #15613
closedEnumerator::Chain#each doesn't relay block signature
Description
Currently, the block given when iterating on the components of a Enumerator::Chain
always have arity of -1 and lambda?
is always false
:
class Foo
include Enumerable
def each(&block)
return to_enum unless block
p block.arity, block.lambda?
end
end
foo = Foo.new
foo.each(&->{}) # => 0, true
foo.each.each(&->{}) # => 0, true
foo.chain.each(&->{}) # => -1, false. Would ideally be 0, true
It would be preferable if the block information wasn't lost.
Files
Updated by marcandre (Marc-Andre Lafortune) almost 6 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r67095.
- spec/ruby: Tweak Enuemrator::Chain#rewind spec so that arity of block matches what is yielded
Calling and_yield(*args)
adds an implicit expectation that all the args
are passed to a block that can accept them, even though blocks that are not lambda-like don't mind extra arguments.
It so happens that this spec passed on Ruby 2.6.1 See [Bug #15613]
Updated by marcandre (Marc-Andre Lafortune) almost 6 years ago
- Status changed from Closed to Open
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
Attached is a patch that fixes this issue by switching from rb_block_call
to rb_funcall_with_block
.
Updated by jeremyevans (Jeremy Evans) about 5 years ago
- Status changed from Open to Closed
Applied in changeset git|a029b54ec716812ade37fef1f857c49f821a8cc8.
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]