From f4d73168fdea09b82662297fe617879d4aa3d3c9 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Thu, 21 May 2026 17:48:20 +0900 Subject: [PATCH] Split parameter-driven return types into overloads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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?`. - `Kernel#system`: `exception: true` raises instead of returning `false`/`nil`, so it can only return `true` — `(exception: true) -> TrueClass`. - `Thread::Queue#pop`: `non_block: true` raises when the queue is empty, so it never returns `nil` — `(true) -> E` / `(?false, ?timeout:) -> E?`. --- core/kernel.rbs | 3 ++- core/thread.rbs | 3 ++- stdlib/bigdecimal/0/big_decimal.rbs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/kernel.rbs b/core/kernel.rbs index fac5a887d..63898ee6f 100644 --- a/core/kernel.rbs +++ b/core/kernel.rbs @@ -2233,7 +2233,8 @@ module Kernel : BasicObject # # Raises an exception if the new process could not execute. # - def self?.system: (String command, *String args, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: bool, ?chdir: String, ?exception: bool) -> (NilClass | FalseClass | TrueClass) + def self?.system: (String command, *String args, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: bool, ?chdir: String, ?exception: false) -> (NilClass | FalseClass | TrueClass) + | (String command, *String args, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: bool, ?chdir: String, exception: true) -> TrueClass | (Hash[string, string?] env, String command, *String args, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: bool, ?chdir: String, ?exception: bool) -> (NilClass | FalseClass | TrueClass) # An interface used with `trace_var` (and `untrace_var`) for custom command types. diff --git a/core/thread.rbs b/core/thread.rbs index b3e7d78c1..7bbaac8ef 100644 --- a/core/thread.rbs +++ b/core/thread.rbs @@ -1719,7 +1719,8 @@ class Thread::Queue[E = untyped] < Object # If `timeout` seconds have passed and no data is available `nil` is returned. # If `timeout` is `0` it returns immediately. # - def pop: (?boolish non_block, ?timeout: _ToF?) -> E? + def pop: (?false non_block, ?timeout: _ToF?) -> E? + | (true non_block) -> E #