I'm seeing unexpected ArgumentError: unknown keyword errors for required keyword arguments when the method has an another optional keyword argument with a default statement (and the optional argument comes before the required one). Here's an example:
puts "RUBY_VERSION: #{RUBY_VERSION}"
puts "JRUBY_VERSION: #{JRUBY_VERSION}" if defined?(JRUBY_VERSION)
def example(optional: (default = true), required:)
return required, optional, default
end
begin
puts example(required: true).to_s
rescue => e
puts e
end
begin
puts example(required: true, optional: true).to_s
rescue => e
puts e
end
Running it with JRuby:
% bin/jruby example.rb
RUBY_VERSION: 3.1.4
JRUBY_VERSION: 9.4.10.0-SNAPSHOT
unknown keyword: :required
unknown keyword: :required
And with regular Ruby:
% ASDF_RUBY_VERSION=3.1.4 ruby example.rb
RUBY_VERSION: 3.1.4
[true, true, true]
[true, true, nil]
% ASDF_RUBY_VERSION=3.4.1 ruby example.rb
RUBY_VERSION: 3.4.1
[true, true, true]
[true, true, nil]
Seems to work ok when the argument order is reversed:
def example(required:, optional: (default = true))
return required, optional, default
end
% bin/jruby example.rb
RUBY_VERSION: 3.1.4
JRUBY_VERSION: 9.4.10.0-SNAPSHOT
[true, true, true]
[true, true, nil]
Or when the default value doesn't assign:
puts "RUBY_VERSION: #{RUBY_VERSION}"
puts "JRUBY_VERSION: #{JRUBY_VERSION}" if defined?(JRUBY_VERSION)
def example(optional: true, required:)
return required, optional
end
begin
puts example(required: true).to_s
rescue => e
puts e
end
begin
puts example(required: true, optional: true).to_s
rescue => e
puts e
end
% bin/jruby example.rb
RUBY_VERSION: 3.1.4
JRUBY_VERSION: 9.4.10.0-SNAPSHOT
[true, true]
[true, true]
Environment Information
I'm seeing unexpected
ArgumentError: unknown keyworderrors for required keyword arguments when the method has an another optional keyword argument with a default statement (and the optional argument comes before the required one). Here's an example:Running it with JRuby:
And with regular Ruby:
Seems to work ok when the argument order is reversed:
Or when the default value doesn't assign:
Environment Information
JRuby (built from master)
Operating system