-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Rubocop crashes on splat operator in case/when block when in auto-correct mode #3597
Comments
It appears to be CaseWhenSplat which is causing the crash. |
@rpherbig, I was not able to reproduce the reported issue with the provided example. I was however able to reproduce the reported issue when there are 2 when branches. results = ['a', 'b']
case 'a'
when *results, 'c'
puts 'true'
when results, 'c'
puts 'true'
else
puts 'false'
end I noticed a different issue for the example that you provided. [8] pry(main)> def splat_first(num)
[8] pry(main)* case num
[8] pry(main)* when *FOO, 6, 7, 8
[8] pry(main)* true
[8] pry(main)* else
[8] pry(main)* false
[8] pry(main)* end
[8] pry(main)* end
=> :splat_first
[9] pry(main)> def splat_last(num)
[9] pry(main)* case num
[9] pry(main)* when 6, 7, 8, *FOO
[9] pry(main)* true
[9] pry(main)* else
[9] pry(main)* false
[9] pry(main)* end
[9] pry(main)* end
=> :splat_last
[17] pry(main)> Benchmark.ips do |x|
[17] pry(main)* x.report('splat first value in splat') { splat_first(3) }
[17] pry(main)* x.report('splat first value not in splat') { splat_first(7) }
[17] pry(main)* x.report('splat first no match') { splat_first(0) }
[17] pry(main)* x.report('splat last value in splat') { splat_last(3) }
[17] pry(main)* x.report('splat last value not in splat') { splat_last(7) }
[17] pry(main)* x.report('splat last no match') { splat_last(0) }
[17] pry(main)* x.compare!
[17] pry(main)* end
Warming up --------------------------------------
splat first value in splat
58.742k i/100ms
splat first value not in splat
57.867k i/100ms
splat first no match 53.724k i/100ms
splat last value in splat
111.219k i/100ms
splat last value not in splat
135.851k i/100ms
splat last no match 113.707k i/100ms
Calculating -------------------------------------
splat first value in splat
708.937k (± 9.9%) i/s - 3.525M in 5.023715s
splat first value not in splat
652.417k (± 9.5%) i/s - 3.241M in 5.013931s
splat first no match 631.900k (± 9.0%) i/s - 3.170M in 5.062059s
splat last value in splat
1.618M (± 6.4%) i/s - 8.119M in 5.039173s
splat last value not in splat
1.907M (± 8.3%) i/s - 9.510M in 5.023153s
splat last no match 1.483M (± 6.9%) i/s - 7.391M in 5.007247s
Comparison:
splat last value not in splat: 1906993.2 i/s
splat last value in splat: 1618336.7 i/s - 1.18x slower
splat last no match: 1483380.3 i/s - 1.29x slower
splat first value in splat: 708936.7 i/s - 2.69x slower
splat first value not in splat: 652417.0 i/s - 2.92x slower
splat first no match: 631900.4 i/s - 3.02x slower tldr: There are two things that should be fixed in this cop. The first is the |
Expected behavior
Running rubocop in auto-correct mode should behave the same as normal mode, but also fix as many issues as possible. This is the output in normal mode:
Actual behavior
However, rubocop crashes on the same code in auto-correct mode:
Steps to reproduce the problem
I made a simple ruby file that demonstrates the problem. Run Rubocop on it twice to see the problem (once with auto-correct, once without):
RuboCop version
The text was updated successfully, but these errors were encountered: