Project

General

Profile

Bug #21807

Updated by taichi730 (Taichi Ishitani) about 24 hours ago

In Ruby 3.4.x, `ArgumentError` @ArgumentError@ is reported when forwarding arguments to a method with intermediate optional arguments. 

 How to reproduce: 

 Execute sample below. 

 ``` ruby 
 class Foo 
   def foo(a = nil, b) 
     p a, b 
   end 
 end 

 class Bar 
   def initialize 
     @foo = Foo.new 
   end 

   def bar(...) 
     @foo.foo(...) 
     @foo.foo(...) 
   end 
 end 

 class Baz 
   def initialize 
     @bar = Bar.new 
   end 

   def baz(_a, ...) 
     @bar.bar(...) 
   end 
 end 

 puts RUBY_VERSION 

 baz = Baz.new 
 baz.baz(0, 1) 
 ``` 

 output: 

 ```console <pre> 
 $ RBENV_VERSION=3.4.8 ruby test.rb 
 3.4.8 
 nil 
 1 
 test.rb:2:in 'foo': wrong number of arguments (given 0, expected 1..2) (ArgumentError) 
         from test.rb:14:in 'Bar#bar' 
         from test.rb:24:in 'Baz#baz' 
 ``` </pre> 

 ```console <pre> 
 $ RBENV_VERSION=3.4.1 ruby test.rb 
 3.4.1 
 nil 
 1 
 test.rb:2:in 'foo': wrong number of arguments (given 0, expected 1..2) (ArgumentError) 
         from test.rb:14:in 'Bar#bar' 
         from test.rb:24:in 'Baz#baz' 
 ``` </pre> 


 For other Ruby verions (e.g. 4.0.0, 3.3.0), no error is reported. 

 ```console <pre> 
 $ RBENV_VERSION=4.0.0 ruby test.rb 
 4.0.0 
 nil 
 1 
 nil 
 1 
 ``` </pre> 

 ```console <pre> 
 $ RBENV_VERSION=3.3.0 ruby test.rb 
 3.3.0 
 nil 
 1 
 nil 
 1 
 ``` </pre>

Back