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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

each_slice adding nils together with a bit destructuring differs from behaviour in CRuby #6048

Open
PragTob opened this issue Jan 30, 2020 · 0 comments

Comments

@PragTob
Copy link

PragTob commented Jan 30, 2020

Hello my friends, it's been too long 馃挌

Sadly, I come to you with a bug today!

For context but otherwise unimportant encountered in simplecov-ruby/simplecov#847 (which will contain a workaround I used after I finished reporting this)

Environment Information

tobi@speedy:~$ ruby -v
jruby 9.2.9.0 (2.5.7) 2019-10-30 458ad3e OpenJDK 64-Bit Server VM 12.0.1+12 on 12.0.1+12 +jit [linux-x86_64]
tobi@speedy:~$ uname -a
Linux speedy 5.3.0-28-generic #30~18.04.1-Ubuntu SMP Fri Jan 17 06:14:09 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Expected Behavior

CRuby behavior as tested in the oldest and newest I have installed (2.4.6 and 2.7.0):

irb(main):001:0> [[1, 1]].each_slice(2).map do |(a1, a2), (b1, b2)| [[a1, a2], [b1, b2]] end
=> [[[1, 1], [nil, nil]]]
irb(main):002:0> [[1, 1]].each_slice(2).map do |slice, slice2| [slice, slice2] end
=> [[[1, 1], nil]]
irb(main):003:0> [[1, 1]].each_slice(2).map do |all| all end
=> [[[1, 1]]]

Actual Behavior

irb(main):001:0>  [[1, 1]].each_slice(2).map do |(a1, a2), (b1, b2)| [[a1, a2], [b1, b2]] end
=> [[[1, nil], [1, nil]]]
irb(main):002:0> [[1, 1]].each_slice(2).map do |slice, slice2| [slice, slice2] end
=> [[1, 1]]
irb(main):003:0> [[1, 1]].each_slice(2).map do |all| all end
=> [[[1, 1]]]

See how the first and second example differ. I'm showing the 3rd example that's the same for completeness sake (aka not everything is different).

1. confuses me the most as to why the 1s that should be together suddenly end up (through the destructuring) ending up in separate elements instead of the one they should be in.
2. JRuby is missing the extra nil here, which it should have as the behaviour of each_slice should be to add in another nil. Somewhat curiously it's also missing a level of array nesting.

Maybe it's also a general problem with each_slice(2) that can be simplified further, I wasn't able to spot anything more though.

Thanks for all your work, enjoy a bunny picture!

IMG_20190927_122528

PragTob added a commit to simplecov-ruby/simplecov that referenced this issue Jan 30, 2020
Works on all the rubies, or let's see what our CI says :)
ref: jruby/jruby#6048
PragTob added a commit to simplecov-ruby/simplecov that referenced this issue Jan 31, 2020
Works on all the rubies, or let's see what our CI says :)
ref: jruby/jruby#6048
PragTob added a commit to simplecov-ruby/simplecov that referenced this issue Jan 31, 2020
Works on all the rubies, or let's see what our CI says :)
ref: jruby/jruby#6048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant