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/IncompatibleIoSelectWithFiberScheduler autocorrect broken when return value is used #10464

Closed
flicken opened this issue Mar 21, 2022 · 0 comments · Fixed by #10480
Closed
Labels

Comments

@flicken
Copy link

flicken commented Mar 21, 2022

Given a file with an IO.select that uses the return values:

rp, wp = IO.pipe
rs, _ = IO.select([rp], [])

Expected behavior

Autocorrect should rewrite to something that is semantically similar, for example:

rp, wp = IO.pipe
rs, _ = rp.wait_readable ? [rp] : []

Actual behavior

Autocorrection is broken:

rp, wp = IO.pipe
rs, _ = rp.wait_readable

Debug output:

rubocop --debug --only Lint/IncompatibleIoSelectWithFiberScheduler -A ioselect.rb
For ~/rubocop-example: configuration from ~/rubocop-example/.rubocop.yml
configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-performance-1.13.3/config/default.yml
configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-performance-1.13.3/config/default.yml
Default configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-1.26.0/config/default.yml
configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-rails-2.14.1/config/default.yml
configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-rails-2.14.1/config/default.yml
configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-rspec-2.9.0/config/default.yml
configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-rspec-2.9.0/config/default.yml
configuration from ~.rvm/gems/ruby-2.7.5/gems/rubocop-sorbet-0.6.7/config/default.yml
configuration from ~/.rvm/gems/ruby-2.7.5/gems/rubocop-sorbet-0.6.7/config/default.yml
Inheriting configuration from ~/rubocop-example/.rubocop_todo.yml
Inspecting 1 file
Scanning ~/rubocop-example/ioselect.rb
W

Offenses:

ioselect.rb:2:9: W: [Corrected] Lint/IncompatibleIoSelectWithFiberScheduler: Use rp.wait_readable instead of IO.select([rp], []).
rs, _ = IO.select([rp], [])
        ^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected
Finished in 1.1718500000424683 seconds

Steps to reproduce the problem

cat >ioselect.rb <<EOF
rp, wp = IO.pipe
rs, _ = IO.select([rp], [])
EOF
rubocop --only Lint/IncompatibleIoSelectWithFiberScheduler -A ioselect.rb

RuboCop version

rubocop -V
1.26.0 (using Parser 3.1.1.0, rubocop-ast 1.16.0, running on ruby 2.7.5 x86_64-darwin21)
  - rubocop-performance 1.13.3
  - rubocop-rails 2.14.1
  - rubocop-rspec 2.9.0
  - rubocop-sorbet 0.6.7
koic added a commit to koic/rubocop that referenced this issue Mar 25, 2022
…leIoSelectWithFiberScheduler`

Fixes rubocop#10464.

This PR fixes an incorrect autocorrect for `Lint/IncompatibleIoSelectWithFiberScheduler`
when using `IO.select` with read (or write) argument and using return value.

When the method is successful the return value of `IO.select` is `[[IO]]`,
and the return value of `io.wait_readable` and `io.wait_writable` are `self`.

They are not auto-corrected when assigning a return value because these types are different.
It's up to user how to handle the return value.
@koic koic added the bug label Mar 25, 2022
bbatsov pushed a commit that referenced this issue Mar 28, 2022
…ectWithFiberScheduler`

Fixes #10464.

This PR fixes an incorrect autocorrect for `Lint/IncompatibleIoSelectWithFiberScheduler`
when using `IO.select` with read (or write) argument and using return value.

When the method is successful the return value of `IO.select` is `[[IO]]`,
and the return value of `io.wait_readable` and `io.wait_writable` are `self`.

They are not auto-corrected when assigning a return value because these types are different.
It's up to user how to handle the return value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants