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

autocorrect for Performance/CaseWhenSplat throws exception #3411

Closed
ptarjan opened this issue Aug 12, 2016 · 0 comments
Closed

autocorrect for Performance/CaseWhenSplat throws exception #3411

ptarjan opened this issue Aug 12, 2016 · 0 comments
Labels

Comments

@ptarjan
Copy link
Contributor

ptarjan commented Aug 12, 2016


Expected behavior

No error

Actual behavior

$ cat a.rb
case foo
when *Foo, Bar
  nil
end
$ rubocop -a a.rb
Inspecting 1 file


0 files inspected, no offenses detected
undefined method `source_range' for nil:NilClass
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/performance/case_when_splat.rb:125:in `reorder_condition'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/performance/case_when_splat.rb:86:in `block in autocorrect'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:57:in `call'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:57:in `block (2 levels) in rewrite'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/parser-2.3.1.2/lib/parser/source/rewriter.rb:194:in `transaction'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:56:in `block in rewrite'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:54:in `each'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/corrector.rb:54:in `rewrite'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:145:in `autocorrect_all_cops'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:77:in `autocorrect'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:105:in `block in offenses'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:122:in `investigate'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:101:in `offenses'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cop/team.rb:52:in `inspect_file'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:223:in `inspect_file'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:193:in `block in do_inspection_loop'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:183:in `loop'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:183:in `do_inspection_loop'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:93:in `block in file_offenses'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:103:in `file_offense_cache'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:91:in `file_offenses'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:82:in `process_file'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:59:in `block in inspect_files'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `each'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:57:in `inspect_files'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/runner.rb:35:in `run'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cli.rb:72:in `execute_runner'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/lib/rubocop/cli.rb:28:in `run'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/bin/rubocop:14:in `block in <top (required)>'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
/Users/pt/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/rubocop-0.42.0/bin/rubocop:13:in `<top (required)>'
/Users/pt/.rbenv/versions/2.2/bin/rubocop:23:in `load'
/Users/pt/.rbenv/versions/2.2/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

see above

RuboCop version

$ rubocop -V
0.42.0 (using Parser 2.3.1.2, running on ruby 2.2.4 x86_64-darwin15)
@bbatsov bbatsov added the bug label Aug 29, 2016
jonas054 added a commit to jonas054/rubocop that referenced this issue Sep 30, 2016
A special case is when there is only one `when` branch, and it has
multiple conditions, with a splat followed by non-splat. This change
only fixes the crash. I think it's possible that reordering the
conditions on the line leads to faster code, but that should be checked.
It's also a more complicated change that could lead to new bugs.
@bbatsov bbatsov closed this as completed in b6b3004 Oct 1, 2016
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
A special case is when there is only one `when` branch, and it has
multiple conditions, with a splat followed by non-splat. This change
only fixes the crash. I think it's possible that reordering the
conditions on the line leads to faster code, but that should be checked.
It's also a more complicated change that could lead to new bugs.
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