Project

General

Profile

Actions

Bug #16801

closed

The default Struct constructor improperly handle keyword arguments

Added by byroot (Jean Boussier) about 4 years ago. Updated almost 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.1p83
[ruby-core:97976]

Description

Reproduction script:

Field = Struct.new(:value) do
  def initialize(value, keyword: false)
    super(value)
    @keyword = keyword
  end
end

Field.new(1, keyword: true)
/tmp/kw.rb:8: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/tmp/kw.rb:2: warning: The called method `initialize' is defined here

This can be worked around with keyword_init: true, but I see no reason why Struct couldn't properly handle keyword arguments in it's default constructor.

I have a patch for this: https://github.com/ruby/ruby/pull/3045 however I had to modify a test that was explicitly expecting that warning, so maybe I'm missing something.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0