Project

General

Profile

Actions

Feature #20211

open

Consider re-adding 3.2-style support of Anonymous Args/Blocks

Added by johnnyshields (Johnny Shields) 10 months ago. Updated 10 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:116438]

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).

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.

Actions #1

Updated by johnnyshields (Johnny Shields) 10 months 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

Also available in: Atom PDF

Like1
Like0