From 60b57866ac64ef8a21951c7d5ff7b7f98e1ce15f Mon Sep 17 00:00:00 2001
From: Masataka Pocke Kuwabara
Date: Tue, 24 Nov 2020 00:37:13 +0900
Subject: [PATCH] [ruby/mutex_m] Fix `Mutex_m#initialize` when the super's
initialize has kwargs
Co-authored-by: Ryuta Kamizono
https://github.com/ruby/mutex_m/commit/84ca1fc108
---
lib/mutex_m.rb | 1 +
test/test_mutex_m.rb | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb
index dd47934bea..07f5a9a0a0 100644
--- a/lib/mutex_m.rb
+++ b/lib/mutex_m.rb
@@ -113,4 +113,5 @@ module Mutex_m
mu_initialize
super
end
+ ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
end
diff --git a/test/test_mutex_m.rb b/test/test_mutex_m.rb
index 30971dd352..e5cfbc8b5f 100644
--- a/test/test_mutex_m.rb
+++ b/test/test_mutex_m.rb
@@ -23,4 +23,36 @@ class TestMutexM < Test::Unit::TestCase
c.signal
assert_equal "abc", t.value
end
+
+ class KeywordInitializeParent
+ def initialize(x:)
+ end
+ end
+
+ class KeywordInitializeChild < KeywordInitializeParent
+ include Mutex_m
+ def initialize
+ super(x: 1)
+ end
+ end
+
+ def test_initialize_with_keyword_arg
+ assert KeywordInitializeChild.new
+ end
+
+ class NoArgInitializeParent
+ def initialize
+ end
+ end
+
+ class NoArgInitializeChild < NoArgInitializeParent
+ include Mutex_m
+ def initialize
+ super()
+ end
+ end
+
+ def test_initialize_no_args
+ assert NoArgInitializeChild.new
+ end
end