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

Performance/RedundantMerge raises error on some double-splat cases #4366

Closed
jlfaber opened this issue May 10, 2017 · 0 comments
Closed

Performance/RedundantMerge raises error on some double-splat cases #4366

jlfaber opened this issue May 10, 2017 · 0 comments

Comments

@jlfaber
Copy link
Contributor

jlfaber commented May 10, 2017

When running merge! on a catch-all function argument, passing a double-splatted hash causes rubocop to raise undefined method 'source' for nil:NilClass


Expected behavior

Rubocop should not raise an error.

Actual behavior

Error in RuboCop::Cop::Performance::RedundantMerge#to_assignments.

Stacktrace:

An error occurred while Performance/RedundantMerge cop was inspecting test2.rb:4:2.
undefined method `source' for nil:NilClass
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:79:in `block in to_assignments'
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:74:in `map'
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:74:in `to_assignments'
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:24:in `block in on_send'
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:53:in `block in each_redundant_merge'
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:18:in `redundant_merge'
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:46:in `each_redundant_merge'
rubocop-0.48.1/lib/rubocop/cop/performance/redundant_merge.rb:23:in `on_send'

Steps to reproduce the problem

def bar(**opts)
  opts.merge!(**foo)
  p opts
end

RuboCop version

$ rubocop -V
0.48.1 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-darwin16)

Ruby version

$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Drenmi added a commit to Drenmi/rubocop that referenced this issue May 15, 2017
…up on double splat argument

This cop would raise an error when encountering a double splat argument:

```
foo.merge!(**bar)
```

This change fixes that.
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