Skip to content

Loading…

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

Closed
kyrylo opened this Issue · 4 comments

4 participants

@kyrylo

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

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

@netoneko

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

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

@BanzaiMan
JRuby Team member

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

@BanzaiMan BanzaiMan closed this
@havenwood havenwood pushed a commit to havenwood/pry that referenced this issue
@kyrylo kyrylo 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.
684ac1f
@kyrylo kyrylo added a commit to pry/pry that referenced this issue
@kyrylo kyrylo 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.
bdb2d79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.