Skip to content

Enumerable#find_index gives wrong result in case with types cast #2902

Closed
@dzjuck

Description

@dzjuck
# Minimal enumerable class
class List
  include ::Enumerable

  def initialize(*items)
    @items = items
  end

  def each(&block)
    @items.each(&block)
  end
end

# Works with array
a = [2]
puts a.find_index(2.0).inspect
#0 # mri
#0 # jruby

# Doesn't work with enumerable
b = List.new(2)
puts b.find_index(2.0).inspect
#0   # mri
# nil # jruby

# Works in another direction
c = List.new(2.0)
puts c.find_index(2).inspect
#0 # mri
#0 # jruby

# Works with comparison in block
d = List.new(2)
puts c.find_index { |i| i == 2.0 }.inspect
#0 # mri
#0 # jruby

Tried with
jruby 1.7.19 (1.9.3p551) 2015-01-29 20786bd on Java HotSpot(TM) 64-Bit Server VM 1.8.0_40-b27 +jit [darwin-x86_64]
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-04-18 06c5d29 Java HotSpot(TM) 64-Bit Server VM 25.40-b25 on 1.8.0_40-b27 +jit [darwin-x86_64]
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-darwin13.4.0]
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin13]

Should i submit specs for this case?

Anybody have ideas how to fix it?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions