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

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

Closed
cbeer opened this issue Aug 6, 2018 · 1 comment
Closed

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

cbeer opened this issue Aug 6, 2018 · 1 comment
Milestone

Comments

@cbeer
Copy link

@cbeer cbeer commented Aug 6, 2018

Environment

jruby -v: jruby 9.2.0.0 (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
end

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

Actual Behavior

In JRuby 9.2.0.0, the single element in not returned:

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

a.slice_when { true }.to_a # => [[]]
mejackreed added a commit to mejackreed/jruby that referenced this issue Aug 7, 2018
Enumerables with 1 element

Fixes jruby#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
otherwise.
@headius
Copy link
Member

@headius headius commented Aug 16, 2018

Thank you for the report!

@headius headius added this to the JRuby 9.2.1.0 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.