diff --git a/core/string.rbs b/core/string.rbs index 6c603af75..e6e9b6ed0 100644 --- a/core/string.rbs +++ b/core/string.rbs @@ -2733,8 +2733,8 @@ class String # <> <> # rceu lowlr # - def scan: (Regexp pattern) -> Array[String | Array[String]] - | (Regexp pattern) { (String | Array[String] matches) -> void } -> self + def scan: (Regexp pattern) -> Array[String | Array[String?]] + | (Regexp pattern) { (String | Array[String?] matches) -> void } -> self | (string pattern) -> Array[String] | (string pattern) { (String match) -> void } -> self diff --git a/test/stdlib/String_test.rb b/test/stdlib/String_test.rb index e6429a41a..60795707c 100644 --- a/test/stdlib/String_test.rb +++ b/test/stdlib/String_test.rb @@ -1259,11 +1259,15 @@ def test_scan 'hello', :scan, /l/ assert_send_type '(Regexp) -> Array[Array[String]]', 'hello', :scan, /(l)/ + assert_send_type '(Regexp) -> Array[Array[nil]]', + 'hello', :scan, /(x)?/ assert_send_type '(Regexp) { (String) -> void } -> String', 'hello', :scan, /l/ do end assert_send_type '(Regexp) { (Array[String]) -> void } -> String', 'hello', :scan, /(l)/ do end + assert_send_type '(Regexp) { (Array[nil]) -> void } -> String', + 'hello', :scan, /(x)?/ do end with_string 'l' do |pattern| assert_send_type '(string) -> Array[String]',