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

Style/CollectionCompact crash when there's AmbiguousOperator on same statement #11173

Closed
Vasfed opened this issue Nov 11, 2022 · 0 comments · Fixed by #11174
Closed

Style/CollectionCompact crash when there's AmbiguousOperator on same statement #11173

Vasfed opened this issue Nov 11, 2022 · 0 comments · Fixed by #11174
Labels

Comments

@Vasfed
Copy link
Contributor

Vasfed commented Nov 11, 2022

Expected behavior

Same offence like with parentheses - Style/CollectionCompact: Use compact instead of reject(&:nil?)

Actual behavior

# rubocop --only Style/CollectionCompact collection_compact.rb -d
For /Users/vasfed/work/insales/rubocop_bug: configuration from /Users/vasfed/work/insales/rubocop_bug/.rubocop.yml
Default configuration from /Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /Users/vasfed/work/insales/rubocop_bug/collection_compact.rb
An error occurred while Style/CollectionCompact cop was inspecting /Users/vasfed/work/insales/rubocop_bug/collection_compact.rb:1:0.
undefined method `end_pos' for nil:NilClass

          range_between(begin_pos_node.loc.selector.begin_pos, end_pos_node.loc.end.end_pos)
                                                                                   ^^^^^^^^
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/style/collection_compact.rb:115:in `range'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/style/collection_compact.rb:86:in `offense_range'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/style/collection_compact.rb:73:in `on_send'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/team.rb:154:in `investigate_partial'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/team.rb:82:in `investigate'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:315:in `inspect_file'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:286:in `loop'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:138:in `block in file_offenses'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:163:in `file_offense_cache'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:137:in `file_offenses'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:128:in `process_file'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:109:in `block in each_inspected_file'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:108:in `each'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:108:in `reduce'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:108:in `each_inspected_file'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:94:in `inspect_files'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/runner.rb:47:in `run'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli.rb:72:in `run_command'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli.rb:79:in `execute_runners'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cli.rb:48:in `run'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/exe/rubocop:19:in `block in <top (required)>'
/Users/vasfed/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/exe/rubocop:19:in `<top (required)>'
/Users/vasfed/.rvm/gems/ruby-3.1.2/bin/rubocop:25:in `load'
/Users/vasfed/.rvm/gems/ruby-3.1.2/bin/rubocop:25:in `<main>'
/Users/vasfed/.rvm/gems/ruby-3.1.2/bin/ruby_executable_hooks:22:in `eval'
/Users/vasfed/.rvm/gems/ruby-3.1.2/bin/ruby_executable_hooks:22:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/CollectionCompact cop was inspecting /Users/vasfed/work/insales/rubocop_bug/collection_compact.rb:1:0.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.38.0 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [x86_64-darwin21]
Finished in 0.11172500008251518 seconds

Steps to reproduce the problem

AllCops: { NewCops: enable }
[].map(&:foo).reject &:nil?

RuboCop version

$ [bundle exec] rubocop -V
1.38.0 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [x86_64-darwin21]
@koic koic added the bug label Nov 12, 2022
koic added a commit to koic/rubocop that referenced this issue Nov 12, 2022
…nCompact`

Fixes rubocop#11173.

This PR fixes an incorrect autocorrect for `Style/CollectionCompact`
when using `reject` with block pass arg and no parentheses.
bbatsov pushed a commit that referenced this issue Nov 12, 2022
Fixes #11173.

This PR fixes an incorrect autocorrect for `Style/CollectionCompact`
when using `reject` with block pass arg and no parentheses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants