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

Lint/AmbiguousRange: self..42 #10185

Closed
schwern opened this issue Oct 14, 2021 · 1 comment · Fixed by #10187
Closed

Lint/AmbiguousRange: self..42 #10185

schwern opened this issue Oct 14, 2021 · 1 comment · Fixed by #10187
Labels

Comments

@schwern
Copy link

schwern commented Oct 14, 2021

Lint/Ambiguous trips when self is part of the range. I don't see the ambiguity, but I might be wrong.

def foo
  self..42
end

Parenthesis do not help, Lint/Ambiguous is still unhappy.

def foo
  (self..42)
end

Parens around self makes Lint/Ambiguous happy, but I don't understand why. But now Style/RedundantParentheses is unhappy.

def foo
  (self)..42
end

rubocop -A goes into an infinite loop between Lint/AmbiguousRange and Style/RedundantParentheses.


Expected behavior

Neither self..42 nor (self..42) seem ambiguous to me. I'd expect Lint/Ambiguous to accept either one. If it must be (self)..42 then Style/RedundantParentheses would be made to accept that.

Actual behavior

Infinite loop between Lint/AmbiguousRange and Style/RedundantParenthesis.

$ cat ~/.rubocop.yml 
Lint/AmbiguousRange:
    Enabled: true
    
$ rubocop --debug -A test.rb
For /Users/schwern/tmp: configuration from /Users/schwern/.rubocop.yml
Default configuration from /Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/config/default.yml
Inspecting 1 file
Scanning /Users/schwern/tmp/test.rb
W

Offenses:

test.rb:4:3: W: [Corrected] Lint/AmbiguousRange: Wrap complex range boundaries with parentheses to avoid ambiguity.
  self..42
  ^^^^
test.rb:4:3: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a keyword.
  (self)..42
  ^^^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /Users/schwern/tmp/test.rb and caused by Lint/AmbiguousRange -> Style/RedundantParentheses
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:298:in `check_for_infinite_loop'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:281:in `block in iterate_until_no_changes'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:280:in `loop'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:280:in `iterate_until_no_changes'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:249:in `do_inspection_loop'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:120:in `process_file'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:100:in `each'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:100:in `reduce'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/runner.rb:47:in `run'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli.rb:71:in `run_command'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli.rb:78:in `execute_runners'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/lib/rubocop/cli.rb:47:in `run'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/exe/rubocop:12:in `block in <top (required)>'
/Users/schwern/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/schwern/.rvm/gems/ruby-2.7.4/gems/rubocop-1.21.0/exe/rubocop:12:in `<top (required)>'
/Users/schwern/.rvm/gems/ruby-2.7.4/bin/rubocop:23:in `load'
/Users/schwern/.rvm/gems/ruby-2.7.4/bin/rubocop:23:in `<main>'
/Users/schwern/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `eval'
/Users/schwern/.rvm/gems/ruby-2.7.4/bin/ruby_executable_hooks:22:in `<main>'
Finished in 0.164305999991484 seconds

Steps to reproduce the problem

Enable Lint/AmbiguousRange.

RuboCop version

$ rubocop -V
1.21.0 (using Parser 3.0.2.0, rubocop-ast 1.12.0, running on ruby 2.7.4 x86_64-darwin20)
@koic koic added the bug label Oct 14, 2021
koic added a commit to koic/rubocop that referenced this issue Oct 14, 2021
Fixes rubocop#10185.

This PR fixes a false positive for `Lint/AmbiguousRange` when using
`self` in a range literal.
@koic
Copy link
Member

koic commented Oct 14, 2021

Thanks for the feedback. This is a false positive of Lint/AmbiguousRange and I've opened #10187.

koic added a commit that referenced this issue Oct 14, 2021
…uous_range

[Fix #10185] Fix a false positive for `Lint/AmbiguousRange`
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