False positive `Lint/Syntax` with ruby 3.3.1 and anonymous rest arg/keyword argument forwarding
kochalex opened this issue · comments
Ruby 3.3.0 changed how anonymous args/keyword args can be used and the newly released 3.3.1 contains a bugfix for some unambiguous/unintentional places where they could be safely used, see: https://bugs.ruby-lang.org/issues/20090
Expected behavior
Rubocop is able to parse & validate code that runs on ruby 3.3.1
Actual behavior
Get Lint/Syntax
errors such as:
Lint/Syntax: anonymous keyword rest parameter is also used within block
Lint/Syntax: anonymous rest parameter is also used within block
Lint/Syntax: unexpected token $end
❯ bundle exec rubocop --debug
For /Users/<username>/repos/rubocop-repo: Default configuration from /Users/<username>/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/rubocop-1.63.3/config/default.yml
Use parallel by default.
Running parallel inspection
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/14b887b108489c87a0ce57f4b58361ea46a3fdc3
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/88559496eb2db1f6bae77024cd89412cfad0a51c
Inspecting 2 files
Scanning /Users/<username>/repos/rubocop-repo/Gemfile
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/14b887b108489c87a0ce57f4b58361ea46a3fdc3
.Scanning /Users/<username>/repos/rubocop-repo/test.rb
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/88559496eb2db1f6bae77024cd89412cfad0a51c
F
Offenses:
test.rb:3:10: F: Lint/Syntax: anonymous keyword rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
puts(**)
^^
test.rb:11:10: F: Lint/Syntax: anonymous rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
puts(*)
^
test.rb:16:1: F: Lint/Syntax: unexpected token $end
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
2 files inspected, 3 offenses detected
Finished in 0.08651399999507703 seconds
Steps to reproduce the problem
Here's a sample test case: (there are more in https://bugs.ruby-lang.org/issues/20090)
def test(**)
[1].each do
puts(**)
end
end
test(a: 1)
def bar(*)
[1].each do
puts(*)
end
end
bar('1')
The code works on ruby 3.3.1 (and did on 3.2), but not 3.3.0:
❯ ruby --version
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
❯ ruby test.rb
{:a=>1}
1
❯ asdf local ruby 3.3.0
❯ ruby test.rb
test.rb:
test.rb:3: anonymous keyword rest parameter is also used within block (SyntaxError)
test.rb:11: anonymous rest parameter is also used within block
❯ bundle exec rubocop
Inspecting 2 files
.F
Offenses:
test.rb:3:10: F: Lint/Syntax: anonymous keyword rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
puts(**)
^^
test.rb:11:10: F: Lint/Syntax: anonymous rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
puts(*)
^
test.rb:16:1: F: Lint/Syntax: unexpected token $end
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
2 files inspected, 3 offenses detected```
RuboCop version
❯ bundle exec rubocop -V
1.63.3 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.3.0) [arm64-darwin23]
This requires a new release from the parser gem: whitequark/parser#1009
The versions ranges on rubocop allow for an updated version of the parser gem, https://github.com/whitequark/parser/releases/tag/v3.3.1.0 - but anyone who's on 3.3.0 may want to stick with previous version of parser, it doesn't have differences for patch versions of ruby.