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

Style/InPatternThen crashes #13097

Closed
akimd opened this issue Aug 8, 2024 · 1 comment · Fixed by #13101
Closed

Style/InPatternThen crashes #13097

akimd opened this issue Aug 8, 2024 · 1 comment · Fixed by #13101
Labels

Comments

@akimd
Copy link

akimd commented Aug 8, 2024

On the following snippet that cop crashes.

$ cat rubocop.rb
def fun1(obj)
  case obj
  in Hash;  1
  in Integer | Symbol | true | nil; 0
  end
end

Expected behavior

Not a crash.

Actual behavior

$ bundle exec rubocop -d --only Style/InPatternThen rubocop.rb
For /Users/akim/src/faveod/langeod: configuration from .rubocop.yml
Default configuration from vendor/ruby/3.3.0/gems/rubocop-1.65.1/config/default.yml
Use parallel by default.
Skipping parallel inspection: only a single file needs inspection
Inspecting 1 file
Scanning rubocop.rb
An error occurred while Style/InPatternThen cop was inspecting rubocop.rb:4:2.
undefined method `join' for an instance of String
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/style/in_pattern_then.rb:51:in `alternative_pattern_source'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/style/in_pattern_then.rb:34:in `on_in_pattern'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:107:in `public_send'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:105:in `each'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:69:in `on_in_pattern'
vendor/ruby/3.3.0/gems/rubocop-ast-1.32.0/lib/rubocop/ast/traversal.rb:140:in `block in on_case'
vendor/ruby/3.3.0/gems/rubocop-ast-1.32.0/lib/rubocop/ast/traversal.rb:140:in `each'
vendor/ruby/3.3.0/gems/rubocop-ast-1.32.0/lib/rubocop/ast/traversal.rb:140:in `on_case'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:71:in `on_case_match'
vendor/ruby/3.3.0/gems/rubocop-ast-1.32.0/lib/rubocop/ast/traversal.rb:154:in `on_def'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:71:in `on_def'
vendor/ruby/3.3.0/gems/rubocop-ast-1.32.0/lib/rubocop/ast/traversal.rb:20:in `walk'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/commissioner.rb:87:in `investigate'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/team.rb:164:in `investigate_partial'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cop/team.rb:102:in `investigate'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:349:in `block in inspect_file'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:348:in `each'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:348:in `flat_map'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:348:in `inspect_file'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:291:in `block in do_inspection_loop'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:325:in `block in iterate_until_no_changes'
<internal:kernel>:187:in `loop'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:318:in `iterate_until_no_changes'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:287:in `do_inspection_loop'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:168:in `block in file_offenses'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:193:in `file_offense_cache'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:167:in `file_offenses'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:158:in `process_file'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:139:in `block in each_inspected_file'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:138:in `each'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:138:in `reduce'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:138:in `each_inspected_file'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:124:in `inspect_files'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/runner.rb:77:in `run'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli/command.rb:11:in `run'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli/environment.rb:18:in `run'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli.rb:122:in `run_command'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli.rb:129:in `execute_runners'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli.rb:51:in `block in run'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli.rb:81:in `profile_if_needed'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/lib/rubocop/cli.rb:43:in `run'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/exe/rubocop:19:in `block in <top (required)>'
/opt/local/lib/ruby3.3/3.3.0/benchmark.rb:313:in `realtime'
vendor/ruby/3.3.0/gems/rubocop-1.65.1/exe/rubocop:19:in `<top (required)>'
vendor/ruby/3.3.0/bin/rubocop:25:in `load'
vendor/ruby/3.3.0/bin/rubocop:25:in `<main>'
C

Offenses:

rubocop.rb:3:10: C: [Correctable] Style/InPatternThen: Do not use in Hash;. Use in Hash then instead.
  in Hash;  1
         ^

1 file inspected, 1 offense detected, 1 offense autocorrectable

1 error occurred:
An error occurred while Style/InPatternThen cop was inspecting rubocop.rb:4:2.
configuration from .rubocop.yml
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.65.1 (using Parser 3.3.4.2, rubocop-ast 1.32.0, running on ruby 3.3.4) [arm64-darwin23]
Finished in 0.08607299998402596 seconds

Steps to reproduce the problem

See above.

RuboCop version

$ bundle exec rubocop -V
1.65.1 (using Parser 3.3.4.2, rubocop-ast 1.32.0, running on ruby 3.3.4) [arm64-darwin23]

Cheers!

@koic koic added the bug label Aug 8, 2024
koic added a commit to koic/rubocop that referenced this issue Aug 8, 2024
Fixes rubocop#13097.

This PR fixes an error for `Style/InPatternThen`
when using alternative pattern matching deeply.
koic added a commit that referenced this issue Aug 8, 2024
…_then

[Fix #13097] Fix an error for `Style/InPatternThen`
@akimd
Copy link
Author

akimd commented Aug 9, 2024

Thanks!

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