Skip to content

Lint/UselessAssignment: crash on splatted nested parallel assignment #14193

@sammiya

Description

@sammiya

Splatted, nested parallel assignment (left, right), *rest = [[:foo, 1], [:bar, 2]] makes the Lint/UselessAssignment cop crash.

(Possibly a variant of #11905)

Expected behavior

RuboCop should finish without crashing.

Actual behavior

BackTrace
RUBOCOP_TARGET_RUBY_VERSION=3.3 rubocop example.rb --debug
For /tmp/rubocop-variableforce-error: Default configuration from /home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning /tmp/rubocop-variableforce-error/example.rb
An error occurred while Lint/UselessAssignment cop was inspecting /tmp/rubocop-variableforce-error/example.rb.
undefined method `source' for nil
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:209:in `remove_local_variable_assignment_part'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:179:in `autocorrect'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:74:in `block (2 levels) in check_for_unused_assignments'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/base.rb:426:in `correct'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/base.rb:210:in `add_offense'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:66:in `block in check_for_unused_assignments'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:59:in `reverse_each'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:59:in `check_for_unused_assignments'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:52:in `block in after_leaving_scope'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:52:in `each_value'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/lint/useless_assignment.rb:52:in `after_leaving_scope'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/force.rb:44:in `public_send'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/force.rb:44:in `block in run_hook'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/force.rb:41:in `each'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/force.rb:41:in `run_hook'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/variable_force.rb:376:in `block (2 levels) in <class:VariableForce>'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/variable_force/variable_table.rb:17:in `invoke_hook'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/variable_force/variable_table.rb:36:in `pop_scope'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/variable_force.rb:85:in `investigate'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/commissioner.rb:164:in `block (2 levels) in invoke_with_argument'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/commissioner.rb:164:in `block in invoke_with_argument'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/commissioner.rb:164:in `each'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/commissioner.rb:164:in `invoke_with_argument'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/commissioner.rb:85:in `investigate'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/team.rb:174:in `investigate_partial'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cop/team.rb:108:in `investigate'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:348:in `block in inspect_file'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:347:in `each'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:347:in `flat_map'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:347:in `inspect_file'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:290:in `block in do_inspection_loop'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:324:in `block in iterate_until_no_changes'
<internal:kernel>:187:in `loop'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:317:in `iterate_until_no_changes'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:286:in `do_inspection_loop'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:167:in `block in file_offenses'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:192:in `file_offense_cache'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:166:in `file_offenses'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:154:in `process_file'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:134:in `each'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:134:in `reduce'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:134:in `each_inspected_file'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:120:in `inspect_files'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/runner.rb:73:in `run'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli/command.rb:11:in `run'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli/environment.rb:18:in `run'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli.rb:122:in `run_command'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli.rb:129:in `execute_runners'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli.rb:51:in `block in run'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli.rb:81:in `profile_if_needed'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/lib/rubocop/cli.rb:43:in `run'
/home/s/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/rubocop-1.75.6/exe/rubocop:19:in `<top (required)>'
/home/s/.asdf/installs/ruby/3.3.6/bin/rubocop:25:in `load'
/home/s/.asdf/installs/ruby/3.3.6/bin/rubocop:25:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/UselessAssignment cop was inspecting /tmp/rubocop-variableforce-error/example.rb.

Steps to reproduce the problem

Create a file named example.rb containing:

# frozen_string_literal: true

(left, right), *rest = [[:foo, 1], [:bar, 2]]

Run RuboCop:

RUBOCOP_TARGET_RUBY_VERSION=3.3 rubocop example.rb --debug

RuboCop version

rubocop -V                                                
1.75.6 (using Parser 3.3.8.0, rubocop-ast 1.44.1, analyzing as Ruby 2.7, running on ruby 3.3.6) [x86_64-linux]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy