From ca95edb122481479ca20227359816f8ccab74304 Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 9 Jun 2026 16:16:10 +0900 Subject: [PATCH] `MatchData#[]` support `%a{implicitly-returns-nil}` In the following case, even though the return value of `Regexp.last_match` cannot possibly be `nil`, the type still retains the possibility of being `nil`. ```rb when /\AArray<(?.+)>\z/ inner_type = Regexp.last_match[:inner_type] ``` Just like `Array#[]` and others, it would be more practical to make the possibility of `nil` implicit. --- core/match_data.rbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/match_data.rbs b/core/match_data.rbs index c64d9b6cf..09b06dd6b 100644 --- a/core/match_data.rbs +++ b/core/match_data.rbs @@ -92,7 +92,7 @@ class MatchData # # # m[:foo] #=> "oge" # - def []: (capture backref, ?nil) -> String? + def []: %a{implicitly-returns-nil} (capture backref, ?nil) -> String | (int start, int length) -> Array[String?] | (range[int?] range) -> Array[String?]