Skip to content

Commit 84ca1fc

Browse files
pockekamipo
andauthored
Fix Mutex_m#initialize when the super's initialize has kwargs
Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
1 parent 2ccebdc commit 84ca1fc

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/mutex_m.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ def initialize(*args) # :nodoc:
113113
mu_initialize
114114
super
115115
end
116+
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
116117
end

test/test_mutex_m.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,36 @@ def test_cv_wait
2323
c.signal
2424
assert_equal "abc", t.value
2525
end
26+
27+
class KeywordInitializeParent
28+
def initialize(x:)
29+
end
30+
end
31+
32+
class KeywordInitializeChild < KeywordInitializeParent
33+
include Mutex_m
34+
def initialize
35+
super(x: 1)
36+
end
37+
end
38+
39+
def test_initialize_with_keyword_arg
40+
assert KeywordInitializeChild.new
41+
end
42+
43+
class NoArgInitializeParent
44+
def initialize
45+
end
46+
end
47+
48+
class NoArgInitializeChild < NoArgInitializeParent
49+
include Mutex_m
50+
def initialize
51+
super()
52+
end
53+
end
54+
55+
def test_initialize_no_args
56+
assert NoArgInitializeChild.new
57+
end
2658
end

0 commit comments

Comments
 (0)