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

An error occurred while Lint/IdentityComparison cop was inspecting #8720

Closed
lopopolo opened this issue Sep 15, 2020 · 1 comment · Fixed by #8722
Closed

An error occurred while Lint/IdentityComparison cop was inspecting #8720

lopopolo opened this issue Sep 15, 2020 · 1 comment · Fixed by #8722
Labels

Comments

@lopopolo
Copy link

RuboCop 0.91.0 crashes on code that parsed and linted correctly with 0.90.0.


Expected behavior

RuboCop successfully lints the file

Actual behavior

Describe here what actually happened.

RuboCop crashes.

$ bundle exec rubocop .
Inspecting 1 file
An error occurred while Lint/IdentityComparison cop was inspecting /Users/lopopolo/dev/artichoke/artichoke/temp/foo.rb:5:4.
To see the complete backtrace run rubocop -d.
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/IdentityComparison cop was inspecting /Users/lopopolo/dev/artichoke/artichoke/temp/foo.rb:5:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.91.0 (using Parser 2.7.1.4, rubocop-ast 0.4.0, running on ruby 2.6.3 x86_64-darwin19)
$ bundle exec rubocop -d .
For /Users/lopopolo/dev/artichoke/artichoke/temp: configuration from /Users/lopopolo/dev/artichoke/artichoke/.rubocop.yml
configuration from /usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-rake-0.5.1/config/default.yml
configuration from /usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-rake-0.5.1/config/default.yml
Default configuration from /usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/config/default.yml
Inspecting 1 file
Scanning /Users/lopopolo/dev/artichoke/artichoke/temp/foo.rb
An error occurred while Lint/IdentityComparison cop was inspecting /Users/lopopolo/dev/artichoke/artichoke/temp/foo.rb:5:4.
undefined method `source' for nil:NilClass
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/lint/identity_comparison.rb:29:in `block in on_send'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/base.rb:333:in `correct'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/base.rb:126:in `add_offense'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/lint/identity_comparison.rb:28:in `on_send'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:122:in `block (2 levels) in trigger_restricted_cops'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:152:in `with_cop_error_handling'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:121:in `block in trigger_restricted_cops'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:120:in `each'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:120:in `trigger_restricted_cops'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:109:in `on_def'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:72:in `on_def'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:101:in `on_class'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:72:in `on_class'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:14:in `walk'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/commissioner.rb:85:in `investigate'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/team.rb:152:in `investigate_partial'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cop/team.rb:83:in `investigate'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:311:in `inspect_file'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:255:in `block in do_inspection_loop'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:289:in `block in iterate_until_no_changes'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:282:in `loop'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:282:in `iterate_until_no_changes'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:251:in `do_inspection_loop'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:128:in `block in file_offenses'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:153:in `file_offense_cache'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:127:in `file_offenses'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:118:in `process_file'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:97:in `block in each_inspected_file'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:96:in `each'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:96:in `reduce'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:96:in `each_inspected_file'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:82:in `inspect_files'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/runner.rb:43:in `run'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cli/command.rb:11:in `run'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cli/environment.rb:18:in `run'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cli.rb:65:in `run_command'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cli.rb:72:in `execute_runners'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/lib/rubocop/cli.rb:41:in `run'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/exe/rubocop:13:in `block in <top (required)>'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.91.0/exe/rubocop:12:in `<top (required)>'
/usr/local/var/rbenv/versions/2.6.3/bin/rubocop:23:in `load'
/usr/local/var/rbenv/versions/2.6.3/bin/rubocop:23:in `<top (required)>'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `load'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:465:in `exec'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:27:in `dispatch'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:18:in `start'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/exe/bundle:30:in `block in <top (required)>'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/var/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/exe/bundle:22:in `<top (required)>'
/usr/local/var/rbenv/versions/2.6.3/bin/bundle:23:in `load'
/usr/local/var/rbenv/versions/2.6.3/bin/bundle:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/IdentityComparison cop was inspecting /Users/lopopolo/dev/artichoke/artichoke/temp/foo.rb:5:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.91.0 (using Parser 2.7.1.4, rubocop-ast 0.4.0, running on ruby 2.6.3 x86_64-darwin19)
Finished in 0.12186599988490343 seconds

Steps to reproduce the problem

mkdir temp
mv foo.rb temp
cd temp
bundle exec rubocop .

With foo.rb contents:

# frozen_string_literal: true

class A
  def bar(other)
    object_id == other.object_id
  end
end

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ bundle exec rubocop -V
0.91.0 (using Parser 2.7.1.4, rubocop-ast 0.4.0, running on ruby 2.6.3 x86_64-darwin19)
@lopopolo
Copy link
Author

lopopolo commented Sep 15, 2020

My usecase for Object#object_id equality comparisons is to prevent infinite recursion when implementing something like Hash#inspect. I believe it is less likely for Object#object_id to get overridden than equal?.

@koic koic added the bug label Sep 15, 2020
koic added a commit to koic/rubocop that referenced this issue Sep 15, 2020
Fixes rubocop#8720.

This PR fixes an error for `Lint/IdentityComparison` when
calling `object_id` method without receiver in LHS or RHS.
bbatsov pushed a commit that referenced this issue Sep 15, 2020
Fixes #8720.

This PR fixes an error for `Lint/IdentityComparison` when
calling `object_id` method without receiver in LHS or RHS.
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