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

`slice_when` and `chunk_when` don't work with an 1-element enumerable #5275

cbeer opened this Issue Aug 6, 2018 · 1 comment


None yet
2 participants

cbeer commented Aug 6, 2018


jruby -v: jruby (2.5.0) 2018-05-24 81156a8 Java HotSpot(TM) 64-Bit Server VM 25.102-b14 on 1.8.0_102-b14 +jit [darwin-x86_64]

uname -a: Darwin ..... 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64

Expected Behavior

I believe this is related to (and an acknowledged caveat of) #4410; I have an Enumerator of an uncertain size, but sometimes contains only a single element. In MRI ruby, when I call slice_when (or chunk_when), I get:

def a
  return self.enum_for(:a) unless block_given?
  yield 1

a.slice_when { true }.to_a # => [[1]]

Actual Behavior

In JRuby, the single element in not returned:

def a
  return self.enum_for(:a) unless block_given?
  yield 1

a.slice_when { true }.to_a # => [[]]

mejackreed added a commit to mejackreed/jruby that referenced this issue Aug 7, 2018

Modifies underlying logic of slice_when / chunk_while to handle
Enumerables with 1 element

Fixes #5275. Instead of checking for size 1 at the beginning, this change sets a
flag that never gets modified if `each_cons(2)` does not get called.
This happens in the case of 1 element Enumerables. The previous
behavior was fine for Enumerables that respond to `size` but fails

This comment has been minimized.

Show comment
Hide comment

headius Aug 16, 2018


Thank you for the report!


headius commented Aug 16, 2018

Thank you for the report!

@headius headius added this to the JRuby milestone Aug 16, 2018

@enebo enebo closed this in #5276 Sep 19, 2018

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