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/MapCompact crash #309

Closed
Vasfed opened this issue Nov 13, 2022 · 0 comments · Fixed by #310
Closed

Performance/MapCompact crash #309

Vasfed opened this issue Nov 13, 2022 · 0 comments · Fixed by #310
Labels
bug Something isn't working

Comments

@Vasfed
Copy link

Vasfed commented Nov 13, 2022

Expected behavior

Offence like

perf.rb:3:16: C: [Correctable] Performance/MapCompact: Use filter_map instead.
var[1] ||= foo.map(&:bar).compact
               ^^^^^^^^^^^^^^^^^^

Actual behavior

For /Users/vasfed/work/rubocop_bug: configuration from /Users/vasfed/work/rubocop_bug/.rubocop.yml
configuration from /Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-performance-1.15.0/config/default.yml
configuration from /Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-performance-1.15.0/config/default.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/rubocop_bug/perf.rb
An error occurred while Performance/MapCompact cop was inspecting /Users/vasfed/work/rubocop_bug/perf.rb:4:11.
undefined method `dot?' for s(:or_asgn,
  s(:send,
    s(:send, nil, :var), :[],
    s(:int, 1)),
  s(:send,
    s(:send,
      s(:send, nil, :foo), :map,
      s(:block_pass,
        s(:sym, :bar))), :compact)):RuboCop::AST::OrAsgnNode

          if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) && chained_method.dot? &&
                                                                                                    ^^^^^
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-performance-1.15.0/lib/rubocop/cop/performance/map_compact.rb:70:in `remove_compact_method'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-performance-1.15.0/lib/rubocop/cop/performance/map_compact.rb:61:in `block in on_send'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/base.rb:346:in `correct'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/base.rb:127:in `add_offense'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-performance-1.15.0/lib/rubocop/cop/performance/map_compact.rb:59: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:136:in `block in on_dstr'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:136:in `each'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-ast-1.23.0/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/Users/vasfed/.rvm/gems/ruby-3.1.2/gems/rubocop-1.38.0/lib/rubocop/cop/commissioner.rb:71:in `on_or_asgn'
/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 Performance/MapCompact cop was inspecting /Users/vasfed/work/rubocop_bug/perf.rb:4:11.
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.20733900007326156 seconds

Steps to reproduce the problem

require: [rubocop-performance]
AllCops: { NewCops: enable }
# frozen_string_literal: true

# newline is important
var[1] ||= foo
           .map(&:bar).compact

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-performance, rubocop-rails, and others) output by rubocop -V,
include them as well. Here's an example:

$ 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]
  - rubocop-performance 1.15.0
@koic koic added the bug Something isn't working label Nov 14, 2022
koic added a commit to koic/rubocop-performance that referenced this issue Nov 14, 2022
Fixes rubocop#309.

This PR fixes an error for `Performance/MapCompact`
when using `map(&:do_something).compact` and there is a line break after
`map.compact` and assigning with `||=`.
@koic koic closed this as completed in #310 Nov 14, 2022
koic added a commit that referenced this issue Nov 14, 2022
…mpact

[Fix #309] Fix an error for `Performance/MapCompact`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants