Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/thread.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ class Thread < Object
# -->
# Returns the current backtrace of the target thread.
#
def backtrace: (*untyped args) -> ::Array[untyped]
def backtrace: %a{implicitly-returns-nil} () -> ::Array[String]
| %a{implicitly-returns-nil} (int start, ?int? length) -> ::Array[String]
| %a{implicitly-returns-nil} (range[int] range) -> ::Array[String]

# <!--
# rdoc-file=thread.c
Expand All @@ -332,7 +334,9 @@ class Thread < Object
# This method behaves similarly to Kernel#caller_locations except it applies to
# a specific thread.
#
def backtrace_locations: (*untyped args) -> ::Array[untyped]?
def backtrace_locations: %a{implicitly-returns-nil} () -> ::Array[Thread::Backtrace::Location]
| %a{implicitly-returns-nil} (int start, ?int? length) -> ::Array[Thread::Backtrace::Location]
| %a{implicitly-returns-nil} (range[int] range) -> ::Array[Thread::Backtrace::Location]

# <!-- rdoc-file=thread.c -->
# Terminates `thr` and schedules another thread to be run, returning the
Expand Down
40 changes: 40 additions & 0 deletions test/stdlib/Thread_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,46 @@ def test_fetch
assert_send_type "(Symbol, false) -> false", th, :fetch, :dog, false
end

def test_backtrace
assert_send_type "() -> Array[String]",
Thread.current, :backtrace
assert_send_type "(Integer) -> Array[String]",
Thread.current, :backtrace, 0
assert_send_type "(Integer, Integer) -> Array[String]",
Thread.current, :backtrace, 0, 1
assert_send_type "(Integer, nil) -> Array[String]",
Thread.current, :backtrace, 0, nil
assert_send_type "(Range[Integer]) -> Array[String]",
Thread.current, :backtrace, 0..1
assert_send_type "(Integer) -> nil",
Thread.current, :backtrace, 10000

t = Thread.new {}
t.join
assert_send_type "() -> nil",
t, :backtrace
end

def test_backtrace_locations
assert_send_type "() -> Array[Thread::Backtrace::Location]",
Thread.current, :backtrace_locations
assert_send_type "(Integer) -> Array[Thread::Backtrace::Location]",
Thread.current, :backtrace_locations, 0
assert_send_type "(Integer, Integer) -> Array[Thread::Backtrace::Location]",
Thread.current, :backtrace_locations, 0, 1
assert_send_type "(Integer, nil) -> Array[Thread::Backtrace::Location]",
Thread.current, :backtrace_locations, 0, nil
assert_send_type "(Range[Integer]) -> Array[Thread::Backtrace::Location]",
Thread.current, :backtrace_locations, 0..1
assert_send_type "(Integer) -> nil",
Thread.current, :backtrace_locations, 10000

t = Thread.new {}
t.join
assert_send_type "() -> nil",
t, :backtrace_locations
end

def test_raise
t = Thread.new do
begin
Expand Down
Loading