-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Description
The Lint/SelfAssignment cop fails to inspect the following Ruby code:
x.[]=Error Message:
An error occurred while Lint/SelfAssignment cop was inspecting my_file.rb
Steps to reproduce the problem
echo "x.[]=" | rubocop -d -s my_file.rbExpected behavior
Should not raise an error. Meaning no undefined method 'send_type?' for nil (NoMethodError)
Actual behavior
The following error is raised by the Lint/SelfAssignment cop:
[REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/lint/self_assignment.rb:111:in 'RuboCop::Cop::Lint::SelfAssignment#handle_key_assignment': undefined method 'send_type?' for nil (NoMethodError)
if value_node.send_type? && value_node.method?(:[]) &&
^^^^^^^^^^^
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/lint/self_assignment.rb:48:in 'RuboCop::Cop::Lint::SelfAssignment#on_send'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:107:in 'Kernel#public_send'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:107:in 'block (2 levels) in RuboCop::Cop::Commissioner#trigger_responding_cops'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:171:in 'RuboCop::Cop::Commissioner#with_cop_error_handling'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:106:in 'block in RuboCop::Cop::Commissioner#trigger_responding_cops'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:105:in 'Array#each'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:105:in 'RuboCop::Cop::Commissioner#trigger_responding_cops'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:69:in 'RuboCop::Cop::Commissioner#on_send'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:168:in 'RuboCop::AST::Traversal#on_block'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_block'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'block in RuboCop::AST::Traversal#on_dstr'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'Array#each'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'RuboCop::AST::Traversal#on_dstr'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_begin'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:168:in 'RuboCop::AST::Traversal#on_block'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_block'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'block in RuboCop::AST::Traversal#on_dstr'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'Array#each'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'RuboCop::AST::Traversal#on_dstr'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_begin'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:164:in 'RuboCop::AST::Traversal#on_class'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_class'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:148:in 'RuboCop::AST::Traversal#on_while'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_module'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'block in RuboCop::AST::Traversal#on_dstr'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'Array#each'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:147:in 'RuboCop::AST::Traversal#on_dstr'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:71:in 'RuboCop::Cop::Commissioner#on_begin'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-ast-1.47.1/lib/rubocop/ast/traversal.rb:20:in 'RuboCop::AST::Traversal#walk'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/commissioner.rb:87:in 'RuboCop::Cop::Commissioner#investigate'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/team.rb:174:in 'RuboCop::Cop::Team#investigate_partial'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cop/team.rb:108:in 'RuboCop::Cop::Team#investigate'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:350:in 'block in RuboCop::Runner#inspect_file'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:349:in 'Array#each'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:349:in 'Enumerable#flat_map'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:349:in 'RuboCop::Runner#inspect_file'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:291:in 'block in RuboCop::Runner#do_inspection_loop'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:326:in 'block in RuboCop::Runner#iterate_until_no_changes'
from <internal:kernel>:168:in 'Kernel#loop'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:319:in 'RuboCop::Runner#iterate_until_no_changes'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:287:in 'RuboCop::Runner#do_inspection_loop'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:167:in 'block in RuboCop::Runner#file_offenses'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:192:in 'RuboCop::Runner#file_offense_cache'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:166:in 'RuboCop::Runner#file_offenses'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:154:in 'RuboCop::Runner#process_file'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:135:in 'block in RuboCop::Runner#each_inspected_file'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:134:in 'Array#each'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:134:in 'Enumerable#reduce'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:134:in 'RuboCop::Runner#each_inspected_file'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:120:in 'RuboCop::Runner#inspect_files'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/runner.rb:73:in 'RuboCop::Runner#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli/command/execute_runner.rb:26:in 'block in RuboCop::CLI::Command::ExecuteRunner#execute_runner'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli/command/execute_runner.rb:52:in 'RuboCop::CLI::Command::ExecuteRunner#with_redirect'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli/command/execute_runner.rb:25:in 'RuboCop::CLI::Command::ExecuteRunner#execute_runner'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli/command/execute_runner.rb:17:in 'RuboCop::CLI::Command::ExecuteRunner#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli/command.rb:11:in 'RuboCop::CLI::Command.run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli/environment.rb:18:in 'RuboCop::CLI::Environment#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:128:in 'RuboCop::CLI#run_command'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:135:in 'RuboCop::CLI#execute_runners'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:54:in 'block in RuboCop::CLI#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:87:in 'RuboCop::CLI#profile_if_needed'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/cli.rb:45:in 'RuboCop::CLI#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/server_command/exec.rb:22:in 'RuboCop::Server::ServerCommand::Exec#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/server_command/base.rb:24:in 'block in RuboCop::Server::ServerCommand::Base::Runner#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/server_command/base.rb:23:in 'Dir.chdir'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/server_command/base.rb:23:in 'RuboCop::Server::ServerCommand::Base::Runner#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/socket_reader.rb:33:in 'block in RuboCop::Server::SocketReader#read!'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/helper.rb:26:in 'RuboCop::Server::Helper.redirect'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/socket_reader.rb:28:in 'RuboCop::Server::SocketReader#read!'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/core.rb:91:in 'RuboCop::Server::Core#read_socket'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/core.rb:66:in 'block in RuboCop::Server::Core#process_input'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/cache.rb:154:in 'RuboCop::Server::Cache.write_pid_file'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/core.rb:65:in 'RuboCop::Server::Core#process_input'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/core.rb:54:in 'block in RuboCop::Server::Core#detach_server'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/core.rb:47:in 'Kernel#fork'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/core.rb:47:in 'RuboCop::Server::Core#detach_server'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/core.rb:39:in 'RuboCop::Server::Core#start'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/client_command/start.rb:42:in 'block in RuboCop::Server::ClientCommand::Start#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/cache.rb:141:in 'RuboCop::Server::Cache.acquire_lock'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/client_command/start.rb:29:in 'RuboCop::Server::ClientCommand::Start#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/cli.rb:93:in 'RuboCop::Server::CLI#run_command'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/cli.rb:83:in 'RuboCop::Server::CLI#process_arguments'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/lib/rubocop/server/cli.rb:49:in 'RuboCop::Server::CLI#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/rubocop-1.81.1/exe/rubocop:8:in '<top (required)>'
from [REDACTED/rbenv]/versions/3.4.6/bin/rubocop:25:in 'Kernel#load'
from [REDACTED/rbenv]/versions/3.4.6/bin/rubocop:25:in '<top (required)>'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/cli/exec.rb:59:in 'Kernel.load'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/cli/exec.rb:59:in 'Bundler::CLI::Exec#kernel_load'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/cli/exec.rb:23:in 'Bundler::CLI::Exec#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/cli.rb:452:in 'Bundler::CLI#exec'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/vendor/thor/lib/thor/command.rb:28:in 'Bundler::Thor::Command#run'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in 'Bundler::Thor::Invocation#invoke_command'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/vendor/thor/lib/thor.rb:538:in 'Bundler::Thor.dispatch'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/cli.rb:35:in 'Bundler::CLI.dispatch'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/vendor/thor/lib/thor/base.rb:584:in 'Bundler::Thor::Base::ClassMethods#start'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/cli.rb:29:in 'Bundler::CLI.start'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/bundler-2.6.9/exe/bundle:28:in 'block in <top (required)>'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/3.4.0/bundler/friendly_errors.rb:117:in 'Bundler.with_friendly_errors'
from [REDACTED/rbenv]/versions/3.4.6/lib/ruby/gems/3.4.0/gems/bundler-2.6.9/exe/bundle:20:in '<top (required)>'
from [REDACTED/my_project]/bin/bundle:3:in 'Kernel#load'
from [REDACTED/my_project]/bin/bundle:3:in '<main>'
An error occurred while Lint/SelfAssignment cop was inspecting my_file.rb:1:0.
RuboCop version
1.81.1 (using Parser 3.3.9.0, Prism 1.5.1, rubocop-ast 1.47.1, analyzing as Ruby 3.4, running on ruby 3.4.6) +server [x86_64-linux]
- rubocop-factory_bot 2.27.1
- rubocop-minitest 0.38.2
- rubocop-rails 2.33.4
Working version
The Ruby snippet worked fine with this RuboCop version:
1.79.1 (using Parser 3.3.9.0, Prism 1.4.0, rubocop-ast 1.46.0, analyzing as Ruby 3.4, running on ruby 3.4.5) +server [x86_64-linux]
- rubocop-factory_bot 2.27.1
- rubocop-minitest 0.38.1
- rubocop-rails 2.32.0