Skip to content

Style/ArgumentsForwarding breaks code in Ruby 2.7 #12117

@chulkilee

Description

@chulkilee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy