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 certain double splat case #6545

Closed
mmedal opened this issue Dec 4, 2018 · 0 comments
Closed

Performance/RedundantMerge raises error on certain double splat case #6545

mmedal opened this issue Dec 4, 2018 · 0 comments
Labels

Comments

@mmedal
Copy link
Contributor

mmedal commented Dec 4, 2018

Appears to be a regression related to an earlier issue: #4366. When running merge!, passing a kwsplat as the sole argument causes rubocop to raise undefined method 'source' for nil:NilClass.


Expected behavior

Rubocop should not raise an error.

Actual behavior

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

An error occurred while Performance/RedundantMerge cop was inspecting  test:55:8.
  undefined method `source' for nil:NilClass
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:99:in `block in to_assignments'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:92:in `map'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:92:in `to_assignments'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:47:in `block in message'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:19:in `redundant_merge_candidate'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:46:in `message'
rubocop-0.60.0/lib/rubocop/cop/cop.rb:128:in `add_offense'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:27:in `block in on_send'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:57:in `block in each_redundant_merge'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:19:in `redundant_merge_candidate'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:54:in `each_redundant_merge'
rubocop-0.60.0/lib/rubocop/cop/performance/redundant_merge.rb:26:in `on_send'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:56:in `each'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:50:in `each'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:100:in `on_def'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:50:in `each'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:150:in `on_while'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
rubocop-0.60.0/lib/rubocop/ast/traversal.rb:13:in `walk'
rubocop-0.60.0/lib/rubocop/cop/commissioner.rb:46:in `investigate'
rubocop-0.60.0/lib/rubocop/cop/team.rb:116:in `investigate'
rubocop-0.60.0/lib/rubocop/cop/team.rb:104:in `offenses'
rubocop-0.60.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
rubocop-0.60.0/lib/rubocop/runner.rb:269:in `inspect_file'
rubocop-0.60.0/lib/rubocop/runner.rb:216:in `block in do_inspection_loop'
rubocop-0.60.0/lib/rubocop/runner.rb:248:in `block in iterate_until_no_changes'
rubocop-0.60.0/lib/rubocop/runner.rb:241:in `loop'
rubocop-0.60.0/lib/rubocop/runner.rb:241:in `iterate_until_no_changes'
rubocop-0.60.0/lib/rubocop/runner.rb:212:in `do_inspection_loop'
rubocop-0.60.0/lib/rubocop/runner.rb:115:in `block in file_offenses'
rubocop-0.60.0/lib/rubocop/runner.rb:133:in `file_offense_cache'
rubocop-0.60.0/lib/rubocop/runner.rb:113:in `file_offenses'
rubocop-0.60.0/lib/rubocop/runner.rb:101:in `process_file'
rubocop-0.60.0/lib/rubocop/runner.rb:78:in `block in each_inspected_file'
rubocop-0.60.0/lib/rubocop/runner.rb:75:in `each'
rubocop-0.60.0/lib/rubocop/runner.rb:75:in `reduce'
rubocop-0.60.0/lib/rubocop/runner.rb:75:in `each_inspected_file'
rubocop-0.60.0/lib/rubocop/runner.rb:67:in `inspect_files'
rubocop-0.60.0/lib/rubocop/runner.rb:39:in `run'
rubocop-0.60.0/lib/rubocop/cli.rb:157:in `execute_runner'
rubocop-0.60.0/lib/rubocop/cli.rb:85:in `execute_runners'
rubocop-0.60.0/lib/rubocop/cli.rb:41:in `run'
rubocop-0.60.0/exe/rubocop:13:in `block in <top (required)>'
ruby-2.5.1/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
rubocop-0.60.0/exe/rubocop:12:in `<top (required)>'
bin/rubocop:23:in `load'
bin/rubocop:23:in `<main>'
bin/ruby_executable_hooks:15:in `eval'
bin/ruby_executable_hooks:15:in `<main>'

Steps to reproduce the problem

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

RuboCop version

$> bundle exec rubocop -V
0.60.0 (using Parser 2.5.3.0, running on ruby 2.5.1 x86_64-darwin17)

Ruby version

$> ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
mmedal added a commit to mmedal/rubocop that referenced this issue Dec 4, 2018
@koic koic added the bug label Dec 5, 2018
@bbatsov bbatsov closed this as completed in d048e1c Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants