Skip to content

Commit f6ab2f9

Browse files
committed
Update {Method,UnboundMethod,Proc}#source_location signatures to match Ruby 4.1
* Needed for ruby/ruby#15580
1 parent fdfffb3 commit f6ab2f9

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

core/method.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class Method
400400
# This method will return `nil` if the method was not defined in Ruby (i.e.
401401
# native).
402402
#
403-
def source_location: () -> [String, Integer]?
403+
def source_location: () -> ([String, Integer]? | [String, Integer, Integer, Integer, Integer]?)
404404

405405
# <!--
406406
# rdoc-file=proc.c

core/proc.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ class Proc
845845
# This method will return `nil` if the Proc was not defined in Ruby (i.e.
846846
# native).
847847
#
848-
def source_location: () -> [String, Integer]?
848+
def source_location: () -> ([String, Integer]? | [String, Integer, Integer, Integer, Integer]?)
849849

850850
# <!--
851851
# rdoc-file=proc.c

core/unbound_method.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class UnboundMethod
300300
# This method will return `nil` if the method was not defined in Ruby (i.e.
301301
# native).
302302
#
303-
def source_location: () -> [String, Integer]?
303+
def source_location: () -> ([String, Integer]? | [String, Integer, Integer, Integer, Integer]?)
304304

305305
# <!--
306306
# rdoc-file=proc.c

test/stdlib/Method_test.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,14 @@ def test_receiver
154154
end
155155

156156
def test_source_location
157-
assert_send_type '() -> [String, Integer]',
158-
METHOD, :source_location
157+
if_ruby(..."4.1") do
158+
assert_send_type '() -> [String, Integer]',
159+
METHOD, :source_location
160+
end
161+
if_ruby("4.1"...) do
162+
assert_send_type '() -> [String, Integer, Integer, Integer, Integer]',
163+
METHOD, :source_location
164+
end
159165
assert_send_type '() -> nil',
160166
method(:__id__), :source_location
161167
end

test/stdlib/Proc_test.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,14 @@ def test_parameters
139139
end
140140

141141
def test_source_location
142-
assert_send_type '() -> [String, Integer]',
143-
proc{}, :source_location
142+
if_ruby(..."4.1") do
143+
assert_send_type '() -> [String, Integer]',
144+
proc{}, :source_location
145+
end
146+
if_ruby("4.1"...) do
147+
assert_send_type '() -> [String, Integer, Integer, Integer, Integer]',
148+
proc{}, :source_location
149+
end
144150
assert_send_type '() -> nil',
145151
Proc.new(&Kernel.method(:print)), :source_location
146152
end

test/stdlib/UnboundMethod_test.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,18 @@ def test_parameters
8989
end
9090

9191
def test_source_location
92-
assert_send_type '() -> [String, Integer]?',
93-
UMETH, :source_location
94-
assert_send_type '() -> [String, Integer]?',
95-
ParamMeths.instance_method(:leading_optional), :source_location
92+
if_ruby(..."4.1") do
93+
assert_send_type '() -> [String, Integer]?',
94+
UMETH, :source_location
95+
assert_send_type '() -> [String, Integer]',
96+
ParamMeths.instance_method(:leading_optional), :source_location
97+
end
98+
if_ruby("4.1"...) do
99+
assert_send_type '() -> [String, Integer, Integer, Integer, Integer]?',
100+
UMETH, :source_location
101+
assert_send_type '() -> [String, Integer, Integer, Integer, Integer]',
102+
ParamMeths.instance_method(:leading_optional), :source_location
103+
end
96104
end
97105

98106
def test_super_method

0 commit comments

Comments
 (0)