Project

General

Profile

Actions

Bug #21807

closed

ArgumentError is reported when forwarding arguments to method with intermediate optional arguments

Bug #21807: ArgumentError is reported when forwarding arguments to method with intermediate optional arguments

Added by taichi730 (Taichi Ishitani) about 20 hours ago. Updated about 17 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
3.4.8 (2025-12-17 revision 995b59f666) +PRISM [x86_64-linux]
[ruby-core:124366]

Description

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

How to reproduce:

Execute sample below.

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:

$ 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'
$ 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'

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

$ RBENV_VERSION=4.0.0 ruby test.rb
4.0.0
nil
1
nil
1
$ RBENV_VERSION=3.3.0 ruby test.rb
3.3.0
nil
1
nil
1

Related issues 1 (0 open1 closed)

Is duplicate of Ruby - Bug #21326: Instruction generation differences between parse.y and prism for `def a(x, ...); b(...); end`ClosedprismActions

Updated by taichi730 (Taichi Ishitani) about 20 hours ago Actions #1

  • Description updated (diff)

Updated by taichi730 (Taichi Ishitani) about 18 hours ago Actions #2

  • ruby -v changed from 3.4.8 to 3.4.8 (2025-12-17 revision 995b59f666) +PRISM [x86_64-linux]

Updated by nobu (Nobuyoshi Nakada) about 17 hours ago Actions #3

  • Is duplicate of Bug #21326: Instruction generation differences between parse.y and prism for `def a(x, ...); b(...); end` added

Updated by nobu (Nobuyoshi Nakada) about 17 hours ago Actions #4 [ruby-core:124369]

  • Status changed from Open to Closed
  • Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.2: DONTNEED, 3.3: DONTNEED, 3.4: REQUIRED, 4.0: DONTNEED

The backport to only 3.4 is required.

Actions

Also available in: PDF Atom