Actions
Feature #20211
openConsider re-adding 3.2-style support of Anonymous Args/Blocks
Feature #20211: Consider re-adding 3.2-style support of Anonymous Args/Blocks
Status:
Open
Assignee:
-
Target version:
-
Description
(My sincere apologies if this issue has already been raised, I didn't see it in Ruby 3.4 backlog.)
As per https://bugs.ruby-lang.org/issues/19370, Ruby 3.3 no longer allows the following:
def m(*) [1, 2, 3].each { |*| p(*) } end m('test', 'test', 'test') #=> Ruby 3.2: p(*) uses args from m(*) #=> test, test, test #=> Ruby 3.3: raises SyntaxError: anonymous rest parameter is also used within block I am concerned because Rubocop auto-corrects Ruby 3.1+ code to syntax which is no longer supported in Ruby 3.3. There may be quite a bit of Ruby code in the wild which breaks on 3.3 (my own app broke in about 50 places).
- Ruby 3.1+: Naming/BlockForwarding (default true)
- Ruby 3.2+: Style/ArgumentsForwarding with UseAnonymousForwarding (default true)
It would be nice if the Ruby 3.4 syntax could allow the old nested syntax, supporting arg shadowing with different behavior between implicit and explicit |*| usage.
def m(*) [1, 2, 3].each { p(*) } end m('test', 'test', 'test') #=> Ruby 3.2: p(*) uses args from m(*) #=> test, test, test #=> Ruby 3.4: p(*) uses args from m(*) #=> test, test, test def m(*) [1, 2, 3].each { |*| p(*) } end m('test', 'test', 'test') #=> Ruby 3.2: p(*) uses args from m(*) #=> test, test, test #=> Ruby 3.4: p(*) uses args from each #=> 1, 2, 3 The same would also apply to anonymous blocks.
Updated by johnnyshields (Johnny Shields) almost 2 years ago
- Subject changed from Reconsider introducing 3.2-style support of Anonymous Args/Blocks to Consider re-adding 3.2-style support of Anonymous Args/Blocks
Actions