Skip to content

Commit c7fd1c0

Browse files
committed
Split parameter-driven return types into overloads
Several methods have a boolean-ish argument that determines the return type. Express each with literal `true`/`false` overloads instead of a single signature with a loose union return: - `Kernel#BigDecimal`: `exception: false` returns `nil` on a conversion failure, so `(?exception: true) -> BigDecimal` / `(exception: false) -> BigDecimal?`. - `Thread::Queue#pop`: `non_block: true` raises `ThreadError` when the queue is empty, so it never returns `nil` — `(true) -> E` / `(?false, ?timeout:) -> E?`.
1 parent fcc1685 commit c7fd1c0

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

core/thread.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,8 @@ class Thread::Queue[E = untyped] < Object
17191719
# If `timeout` seconds have passed and no data is available `nil` is returned.
17201720
# If `timeout` is `0` it returns immediately.
17211721
#
1722-
def pop: (?boolish non_block, ?timeout: _ToF?) -> E?
1722+
def pop: (?false non_block, ?timeout: _ToF?) -> E?
1723+
| (true non_block) -> E
17231724

17241725
# <!--
17251726
# rdoc-file=thread_sync.c

stdlib/bigdecimal/0/big_decimal.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,8 @@ module Kernel
12381238
# Raises an exception if `value` evaluates to a Float and `digits` is larger
12391239
# than Float::DIG + 1.
12401240
#
1241-
def self?.BigDecimal: (real | string | BigDecimal initial, ?int digits, ?exception: bool) -> BigDecimal
1241+
def self?.BigDecimal: (real | string | BigDecimal initial, ?int digits, ?exception: true) -> BigDecimal
1242+
| (real | string | BigDecimal initial, ?int digits, exception: false) -> BigDecimal?
12421243
end
12431244

12441245
%a{annotate:rdoc:skip}

0 commit comments

Comments
 (0)