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

Failure in Lint/SelfAssignment #8422

Closed
tas50 opened this issue Jul 31, 2020 · 2 comments · Fixed by #8428 or #11865
Closed

Failure in Lint/SelfAssignment #8422

tas50 opened this issue Jul 31, 2020 · 2 comments · Fixed by #8428 or #11865
Labels

Comments

@tas50
Copy link
Contributor

tas50 commented Jul 31, 2020

Expected behavior

Cop runs

Actual behavior

Cop throws error

Steps to reproduce the problem

Run rubocop with: bundle exec rubocop --only Lint/SelfAssignment /Users/tsmith/dev/oss/IT-CPE_facebook/itchef/cookbooks/cpe_applocker/libraries/applocker_helpers.rb -d

against:

https://github.com/facebook/IT-CPE/blob/master/itchef/cookbooks/cpe_applocker/libraries/applocker_helpers.rb

An error occurred while Lint/SelfAssignment cop was inspecting /Users/tsmith/dev/oss/IT-CPE_facebook/itchef/cookbooks/cpe_applocker/libraries/applocker_helpers.rb:23:4.
undefined method `const_type?' for nil:NilClass
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/lint/self_assignment.rb:43:in `on_casgn'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:91:in `block (2 levels) in trigger_responding_cops'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:112:in `with_cop_error_handling'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:90:in `block in trigger_responding_cops'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:89:in `each'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:89:in `trigger_responding_cops'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:61:in `block (2 levels) in <class:Commissioner>'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:59:in `block in on_or_asgn'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:59:in `each'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:59:in `on_or_asgn'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:62:in `block (2 levels) in <class:Commissioner>'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:59:in `block in on_begin'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:59:in `each'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:59:in `on_begin'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:62:in `block (2 levels) in <class:Commissioner>'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:159:in `on_while'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:62:in `block (2 levels) in <class:Commissioner>'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:159:in `on_while'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:62:in `block (2 levels) in <class:Commissioner>'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-ast-0.2.0/lib/rubocop/ast/traversal.rb:14:in `walk'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/commissioner.rb:74:in `investigate'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:151:in `investigate_partial'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:295:in `inspect_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:245:in `block in do_inspection_loop'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:277:in `block in iterate_until_no_changes'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:270:in `loop'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:270:in `iterate_until_no_changes'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:241:in `do_inspection_loop'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:121:in `block in file_offenses'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:146:in `file_offense_cache'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:120:in `file_offenses'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:111:in `process_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:90:in `block in each_inspected_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:89:in `each'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:89:in `reduce'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:89:in `each_inspected_file'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:78:in `inspect_files'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/runner.rb:39:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/command.rb:10:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli/environment.rb:17:in `run'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli.rb:65:in `run_command'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/tsmith/dev/oss/rubocop/lib/rubocop/cli.rb:41:in `run'
/Users/tsmith/dev/oss/rubocop/exe/rubocop:13:in `block in <top (required)>'
/usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/tsmith/dev/oss/rubocop/exe/rubocop:12:in `<top (required)>'
/usr/local/lib/ruby/gems/2.7.0/bin/rubocop:23:in `load'
/usr/local/lib/ruby/gems/2.7.0/bin/rubocop:23:in `<top (required)>'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/opt/ruby/bin/bundle:23:in `load'
/usr/local/opt/ruby/bin/bundle:23:in `<main>'

RuboCop version

master
@koic koic added the bug label Jul 31, 2020
koic added a commit to koic/rubocop that referenced this issue Jul 31, 2020
Fixes rubocop#8422.

Fix an error for `Lint/SelfAssignment` when using or-assignment for constant.
bbatsov pushed a commit that referenced this issue Jul 31, 2020
Fixes #8422.

Fix an error for `Lint/SelfAssignment` when using or-assignment for constant.
@elia
Copy link

elia commented May 9, 2023

I'm getting the same error with the following code:

A = if foo
  bar
else
end

Full check:

⤑ be rubocop --force-default-config --raise-cop-error --debug tmp/foo.rb
Default configuration from /Users/elia/.asdf/installs/ruby/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.50.2/config/default.yml
Inspecting 1 file
Scanning /Users/elia/Code/Opal/opal/tmp/foo.rb
.

0 files inspected, no offenses detected
Error: cause: #<NoMethodError: undefined method `const_type?' for nil:NilClass

          node.branches.any?(&:const_type?)
                       ^^^^^>
Finished in 0.07879599998705089 seconds
⤑ cat tmp/foo.rb
A = if foo
  bar
else
end
⤑ be rubocop -v
1.50.2

koic added a commit to koic/rubocop that referenced this issue May 9, 2023
Fixes rubocop#8422 (comment).

This PR fixes an error for `Naming/ConstantName`
when assigning a constant from an empty branch of `else`.
@koic
Copy link
Member

koic commented May 9, 2023

@elia Thank you for the feedback. I opened #11865 to resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants