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

Unexpected behaviour of `Enumerator#find_index` with block (1.9 mode and HEAD) #525

Closed
kyrylo opened this Issue Feb 4, 2013 · 4 comments

Comments

Projects
None yet
4 participants
@kyrylo
Copy link
Contributor

kyrylo commented Feb 4, 2013

Please, note that Enumerable#find_index on its own works fine. The problem is with Enumerator.

✗ JRUBY_OPTS=--1.9
. .
JRUBY_VERSION 1.7.2
JRUBY_REVISION 302c706
RUBY_VERSION 1.9.3
ENV_JAVA['jruby.enumerator.lightweight'] nil
enum = Enumerator.new { |y| y.yield :fail }
#=> #<Enumerator: ...>
enum.to_a
#=> [:fail]
enum.find_index
#=> #<Enumerator: ...>
enum.find_index(:fail)
#=> 0
enum.find_index { |e| e }
#=> nil
enum.to_a.find_index { |e| e }
#=> 0
✓ JRUBY_OPTS=--1.8
. .
JRUBY_VERSION 1.7.2
JRUBY_REVISION 302c706
RUBY_VERSION 1.8.7
ENV_JAVA['jruby.enumerator.lightweight'] nil
require 'generator'
#=> true
enum = Generator.new { |y| y.yield :success }
#=> #<JRuby::Generator::Threaded: ...>
enum.to_a
#=> [:success]
enum.find_index
#=> #<Enumerable::Enumerator: ...>
enum.find_index(:success)
#=> 0
enum.find_index { |e| e }
#=> 0
✓ MRI 1.9.3
. .
RUBY_VERSION 1.9.3
RUBY_REVISION 38858
enum = Enumerator.new { |y| y.yield :success }
#=> #<Enumerator: ...>
enum.to_a
#=> [:success]
enum.find_index
#=> #<Enumerator: ...>
enum.find_index(:success)
#=> 0
enum.find_index { |e| e }
#=> 0
@sluukkonen

This comment has been minimized.

Copy link
Contributor

sluukkonen commented Feb 13, 2013

Similarly, Enumerator.new { |y| y.yield :foo }.find_index.to_a will throw a NullPointerException.

@netoneko

This comment has been minimized.

Copy link

netoneko commented Feb 13, 2013

Look at this piece of code:

callEach(runtime, context, self, Arity.NO_ARGUMENTS, new BlockCallback() {

If you replace Arity.NO_ARGUMENTS with Arity.ONE_ARGUMENT, everything works just fine.

Should I create a pull request for this?

@sluukkonen

This comment has been minimized.

Copy link
Contributor

sluukkonen commented Feb 13, 2013

Yeah, I found out the same thing. I was just about to make a pull request.

@BanzaiMan

This comment has been minimized.

Copy link
Member

BanzaiMan commented Feb 15, 2013

@sluukkonen's fix was merged to the master branch as de1abd0. Thank you.

@BanzaiMan BanzaiMan closed this Feb 15, 2013

havenwood pushed a commit to havenwood/pry that referenced this issue Nov 12, 2013

WrappedModule#candidates: return Array on JRuby >=1.9
JRuby 1.9 has a nasty bug with `Enumerator#find_index`, which we utilise
in the code of `whereami` command.

More information on the bug: jruby/jruby#525

Simply return an Array, formed from the original Enumerator on JRuby 1.9
and higher. This kills the efficiency, but leastwise, it will be
working.

As a bonus, remove some a junk method.

kyrylo added a commit to pry/pry that referenced this issue Mar 18, 2015

WrappedModule#candidates: return Array on JRuby >=1.9
JRuby 1.9 has a nasty bug with `Enumerator#find_index`, which we utilise
in the code of `whereami` command.

More information on the bug: jruby/jruby#525

Simply return an Array, formed from the original Enumerator on JRuby 1.9
and higher. This kills the efficiency, but leastwise, it will be
working.

As a bonus, remove some a junk method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.