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/ArgumentsForwarding breaks code in Ruby 2.7 #12117

Closed
chulkilee opened this issue Aug 11, 2023 · 0 comments
Closed

Style/ArgumentsForwarding breaks code in Ruby 2.7 #12117

chulkilee opened this issue Aug 11, 2023 · 0 comments

Comments

@chulkilee
Copy link
Contributor

Example code:

class Foo
  def bar(*args, &block)
    hello(*args, &block)
    world(*args)
  end
end

Expected behavior

Output code should be working code after autofix.

Actual behavior

$ bundle exec rubocop -a test.rb`
...

test.rb:3:13: C: [Corrected] Style/ArgumentsForwarding: Use shorthand syntax ... for arguments forwarding.
    def bar(*args, &block)
            ^^^^^^^^^^^^^
test.rb:4:12: C: [Corrected] Style/ArgumentsForwarding: Use shorthand syntax ... for arguments forwarding.
      puts(*args, &block)
           ^^^^^^^^^^^^^

Result

class Foo
  class << self
    def bar(...)
      puts(...)
      puts(*args)
    end
  end
end

This is broken since args is not defined anymore.

Please note it happens when running on 3.2.0 with TargetRubyVersion: 2.7.

If I run it on 3.2.0 with TargetRubyVersion: 3.2, output is:

class Foo
  class << self
    def bar(*, &block)
      puts(*, &block)
      puts(*)
    end
  end
end

And this is not working on ruby 2.7

Steps to reproduce the problem

Gemfile

source 'https://rubygems.org'

gem 'rubocop', '1.56.0'

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    ast (2.4.2)
    base64 (0.1.1)
    json (2.6.3)
    language_server-protocol (3.17.0.3)
    parallel (1.23.0)
    parser (3.2.2.3)
      ast (~> 2.4.1)
      racc
    racc (1.7.1)
    rainbow (3.1.1)
    regexp_parser (2.8.1)
    rexml (3.2.6)
    rubocop (1.56.0)
      base64 (~> 0.1.1)
      json (~> 2.3)
      language_server-protocol (>= 3.17.0)
      parallel (~> 1.10)
      parser (>= 3.2.2.3)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 1.8, < 3.0)
      rexml (>= 3.2.5, < 4.0)
      rubocop-ast (>= 1.28.1, < 2.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 2.4.0, < 3.0)
    rubocop-ast (1.29.0)
      parser (>= 3.2.1.0)
    ruby-progressbar (1.13.0)
    unicode-display_width (2.4.2)

PLATFORMS
  arm64-darwin-22

DEPENDENCIES
  rubocop (= 1.56.0)

BUNDLED WITH
   2.4.12

.rubocop.yml

AllCops:
  TargetRubyVersion: 2.7

Style/ArgumentsForwarding:
  Enabled: true
$ ruby --version
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [arm64-darwin22]

$ bundle exec rubocop -V
1.56.0 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 2.7.8) [arm64-darwin22]

$ cat .tool-versions
ruby 2.7.8
@koic koic closed this as completed in 62a7cb9 Aug 13, 2023
koic added a commit that referenced this issue Aug 13, 2023
…thout_block

[Fix #12117] Fix `Style/ArgumentsForwarding` when not always forwarding a block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant