-
-
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
Performance/PushSplat autocorrect can lead to runtime error #3292
Comments
So the main problem here is that, by definition, every variable may be So the options are then:
|
Impossible. 😛
It could still work for literals. |
Yes. Literals are the exception. |
Hm. I've been benchmarking this, and no matter what parameters I use, the "fast" version is consistently 4% slower. Might be that Ruby internals changed and this is no longer relevant. Since the performance is minuscule, I'd suggest we drop this cop altogether. (Unless we want to move the cop to |
It's not just
While push(*x) does convert a hash into an array of arrays, concat does not. |
I've confirmed that the cop can produce code that's slower and/or crashes. I agree that we have to remove it. PR coming up. |
This cop's auto-correct (or manual correction based on its recommendations) can produce code that is slower or code that fails for various reasons.
This cop's auto-correct (or manual correction based on its recommendations) can produce code that is slower or code that fails for various reasons.
Actual behavior
With a push splat where the argument may be
nil
autocorrect will still change it and then the code will throw a TypeError (asArray#concat
cannot handlenil
arguments).Expected behavior
Autocorrect should not cause breaking changes to codebase. Therefore when auto-correcting a push splat where the argument may be nil it should either not correct it, or maybe coerce it to an array with
#to_a
.Steps to reproduce the problem
Put this code somewhere:
Run the code, see that it doesn't raise an exception.
Run RuboCop with autocorrect, see it makes 1 change.
Run the code again, see that it now raises a
TypeError
.RuboCop version
I've tested this on
master
too, still applies.The text was updated successfully, but these errors were encountered: