Project

General

Profile

Actions

Bug #15613

closed

Enumerator::Chain#each doesn't relay block signature

Added by marcandre (Marc-Andre Lafortune) about 5 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
[ruby-core:91600]

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

enum-chain-lambda-15613.patch (2.02 KB) enum-chain-lambda-15613.patch jeremyevans0 (Jeremy Evans), 08/28/2019 11:45 PM
Actions #1

Updated by marcandre (Marc-Andre Lafortune) about 5 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]

Actions #2

Updated by marcandre (Marc-Andre Lafortune) about 5 years ago

  • Status changed from Closed to Open

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

Attached is a patch that fixes this issue by switching from rb_block_call to rb_funcall_with_block.

Actions #4

Updated by jeremyevans (Jeremy Evans) over 4 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]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0