Bug #16465
closedFalse keyword warning against Struct#initialize
Description
The following code is warned:
Sample2 = Struct.new(:s1, :s2, :s3) do
def initialize(a1:, a2:)
super(a1, a2, a1 + a2)
end
end
p Sample2.new(a1:1, a2:2)
#=> test.rb:6: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
#=> test.rb:2: warning: The called method `initialize' is defined here
I think the code is innocent and the warning is false positive. I'll create a pull request.
Updated by mame (Yusuke Endoh) almost 5 years ago
It was reported in http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/50860
Updated by mame (Yusuke Endoh) almost 5 years ago
Updated by nobu (Nobuyoshi Nakada) almost 5 years ago
Your patch seems eventually same as:
diff --git a/struct.c b/struct.c
index 79131db2bd..07bfe59b97 100644
--- a/struct.c
+++ b/struct.c
@@ -326,9 +326,7 @@ static VALUE
setup_struct(VALUE nstr, VALUE members, int keyword_init)
{
long i, len;
- VALUE (*new_func)(int, const VALUE *, VALUE) = rb_class_new_instance;
-
- if (keyword_init) new_func = struct_new_kw;
+ VALUE (*new_func)(int, const VALUE *, VALUE) = struct_new_kw;
members = struct_set_members(nstr, members);
Updated by Anonymous over 4 years ago
- Status changed from Open to Closed
Applied in changeset git|adf709a78534c1483ba851ccb0490464ca31503c.
Classes made from Struct should have default new
singleton method.
[Bug #16465] [Bug #16801]
[Fix GH-2795] [Fix GH-2944] [Fix GH-3045] [Fix GH-3093]
Note: Backporting shouldn't modify object.h and instead can use
struct_new_kw which is basically a duplicate implementation of
rb_class_new_instance_pass_kw
Co-authored-by: Yusuke Endoh mame@ruby-lang.org
Co-authored-by: John Hawthorn john@hawthorn.email
Co-authored-by: Adam Hess HParker@github.com
Co-authored-by: Jose Cortinas jacortinas@gmail.com
Co-authored-by: Jean Boussier jean.boussier@gmail.com