From 131ec174b50e113bb1e26a828a868b6f04386a1b Mon Sep 17 00:00:00 2001 From: ksss Date: Fri, 25 Sep 2026 17:14:58 +0900 Subject: [PATCH] Add implicitly-returns-nil to Kernel#caller and #caller_locations They return nil only when start exceeds the stack depth, which almost never happens in practice (even at the top level, caller(1) returns []). Treating the result as non-nil lets common idioms such as caller_locations(1, 1).first type-check without a nil guard, matching Exception#backtrace. Co-Authored-By: Claude Opus 5.5 --- core/kernel.rbs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/kernel.rbs b/core/kernel.rbs index fac5a887d5..be48950a6e 100644 --- a/core/kernel.rbs +++ b/core/kernel.rbs @@ -183,8 +183,8 @@ module Kernel : BasicObject # c(5) #=> nil # def self?.caller: () -> Array[String] - | (int start, ?int? length) -> Array[String]? - | (range[int] range) -> Array[String]? + | %a{implicitly-returns-nil} (int start, ?int? length) -> Array[String] + | %a{implicitly-returns-nil} (range[int] range) -> Array[String] #