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/MultilineTernaryOperator may create infinite loop #10592

Closed
sevenc-nanashi opened this issue Apr 30, 2022 · 0 comments · Fixed by #10594
Closed

Style/MultilineTernaryOperator may create infinite loop #10592

sevenc-nanashi opened this issue Apr 30, 2022 · 0 comments · Fixed by #10594
Labels

Comments

@sevenc-nanashi
Copy link

Style/MultilineTernaryOperator created infinite loop in specific code below.

Expected behavior

No error.

Actual behavior

For E:/tmp: configuration from E:/tmp/.rubocop.yml                                                                          
Default configuration from C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/config/default.yml                     
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in
...(omit)...                                                                                                       
For more information: https://docs.rubocop.org/rubocop/versioning.html                                                      
Inspecting 1 file
Scanning E:/tmp/test.rb
C

Offenses:

test.rb:4:3: C: [Corrected] Style/MultilineTernaryOperator: Avoid multi-line ternary operators, use single-line instead.    
  b == ...
  ^^^^

0 files inspected, 1 offense detected, 1 offense corrected
Infinite loop detected in E:/tmp/test.rb and caused by Style/MultilineTernaryOperator
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:296:in `check_for_infinite_loop'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:279:in `block in iterate_until_no_changes'  
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:278:in `loop'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:278:in `iterate_until_no_changes'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:247:in `do_inspection_loop'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:130:in `block in file_offenses'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:155:in `file_offense_cache'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:129:in `file_offenses'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:120:in `process_file'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:101:in `block in each_inspected_file'       
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:100:in `each'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:100:in `reduce'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:100:in `each_inspected_file'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:86:in `inspect_files'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:47:in `run'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'   
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'  
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli/command.rb:11:in `run'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli/environment.rb:18:in `run'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:71:in `run_command'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:78:in `execute_runners'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:47:in `run'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/exe/rubocop:12:in `block in <top (required)>'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/benchmark-0.2.0/lib/benchmark.rb:311:in `realtime'
C:/develop/Ruby30/lib/ruby/gems/3.0.0/gems/rubocop-1.28.2/exe/rubocop:12:in `<top (required)>'
C:/develop/Ruby30/bin/rubocop:25:in `load'
C:/develop/Ruby30/bin/rubocop:25:in `<main>'
Finished in 0.8523308001458645 seconds                                                                                     

Steps to reproduce the problem

Format this with -A option. No config required.

a[:a] =
  b ==
    c ? d : e

RuboCop version

1.28.2 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 3.0.3 i386-mingw32)
@koic koic added the bug label Apr 30, 2022
nobuyo added a commit to nobuyo/rubocop that referenced this issue Apr 30, 2022
…tor` if using assignment method and condition/branch is multiline

Update lib/rubocop/cop/style/multiline_ternary_operator.rb

Co-authored-by: Koichi ITO <koic.ito@gmail.com>
koic added a commit that referenced this issue Apr 30, 2022
…iline-ternary-operator

[Fix #10592] Fix infinite loop on `Style/MultilineTernaryOperator`
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