Skip to content

ruby2_keywords + forwarding to native does not properly check arity #8398

@kalenp

Description

@kalenp

When combining ruby2_keywords with alias_method or alias, arguments are not handled properly. This appears to require a built in function, since I'm not able to reproduce this with a normal function which I alias and redefine. The same issue occurs with both alias and alias_method.

Basic Repro:

class File
  class << self
    alias original_write write

    ruby2_keywords def write(*args, &block)
      puts "traced #{__method__}"
      original_write(*args, &block)
    end

  end
end


File.write('scratch', "stuff", 0, mode: 'a+')

On MRI:

$ /usr/bin/ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]
$ /usr/bin/ruby test.rb
traced write
$ 

On JRuby:

$ jruby --version
jruby 9.4.8.0 (3.1.4) 2024-07-02 4d41e55a67 OpenJDK 64-Bit Server VM 11.0.15+0-adhoc..source on 11.0.15+0-adhoc..source +jit [x86_64-linux]
$ jruby test.rb
traced write
ArgumentError: wrong number of arguments (given 4, expected 2..3)
   write at org/jruby/RubyIO.java:4290
   write at temp.rb:7
  <main> at temp.rb:13
$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions