Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dzjuck opened this issue May 1, 2015 · 1 comment
Closed

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

dzjuck opened this issue May 1, 2015 · 1 comment

Comments

@dzjuck
Copy link

dzjuck commented May 1, 2015

# 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.

@enebo enebo closed this as completed in 5dc447a May 1, 2015
enebo added a commit that referenced this issue May 1, 2015
…pes cast

Conflicts:
	core/src/main/java/org/jruby/RubyEnumerable.java
@enebo
Copy link
Member

enebo commented May 1, 2015

Also fixed on jruby-1_7 in commit f131465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants