From 191436847a55443eaf2b4014f03f41615b19c5b5 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Wed, 17 Jun 2026 12:04:27 +0200 Subject: [PATCH] Allow nil output buffers for reader methods Ruby accepts explicit nil for output buffer arguments and allocates a new String in that case. Update signatures and stdlib tests to match. Updated signatures: * _Reader#read * _ReaderPartial#readpartial * IO#{pread,read_nonblock,readpartial,sysread} * ARGF#{read,read_nonblock,readpartial} * StringIO#{read,pread,read_nonblock,readpartial,sysread} * Zlib::GzipReader#read,readpartial * OpenSSL::Buffering#{read,read_nonblock,readpartial} * OpenSSL::SSL::SSLSocket#sysread --- core/builtin.rbs | 4 +-- core/io.rbs | 14 +++++------ core/rbs/unnamed/argf.rbs | 6 ++--- stdlib/openssl/0/openssl.rbs | 10 ++++---- stdlib/stringio/0/stringio.rbs | 10 ++++---- stdlib/zlib/0/gzip_reader.rbs | 4 +-- test/stdlib/ARGF_test.rb | 8 ++++++ test/stdlib/IO_test.rb | 38 +++++++++++++++++++++++++++++ test/stdlib/OpenSSL_test.rb | 32 ++++++++++++++++++++++++ test/stdlib/StringIO_test.rb | 27 ++++++++++++++++++++ test/stdlib/zlib/GzipReader_test.rb | 30 +++++++++++++++++++++++ 11 files changed, 159 insertions(+), 24 deletions(-) diff --git a/core/builtin.rbs b/core/builtin.rbs index cac44450b0..8bee589d89 100644 --- a/core/builtin.rbs +++ b/core/builtin.rbs @@ -179,11 +179,11 @@ interface _EachEntry[out T] end interface _Reader - def read: (?int? length, ?string outbuf) -> String? + def read: (?int? length, ?string? outbuf) -> String? end interface _ReaderPartial - def readpartial: (int maxlen, ?string outbuf) -> String + def readpartial: (int maxlen, ?string? outbuf) -> String end interface _Writer diff --git a/core/io.rbs b/core/io.rbs index 1b6f79bb95..d31a5b1d83 100644 --- a/core/io.rbs +++ b/core/io.rbs @@ -1492,7 +1492,7 @@ class IO < Object # # Not available on some platforms. # - def pread: (int maxlen, int offset, ?string out_string) -> String + def pread: (int maxlen, int offset, ?string? out_string) -> String # # The "sync mode" of the SSLSocket. @@ -9235,7 +9235,7 @@ module OpenSSL # Reads *length* bytes from the SSL connection. If a pre-allocated *buffer* is # provided the data will be written into it. # - def sysread: (Integer length, ?String buffer) -> String + def sysread: (Integer length, ?String? buffer) -> String # # See IO#read. # - def read: (?int? length, ?string outbuf) -> String? + def read: (?int? length, ?string? outbuf) -> String? # # See IO#pread. # - def pread: (Integer maxlen, Integer offset, ?String outbuf) -> String + def pread: (Integer maxlen, Integer offset, ?String? outbuf) -> String - def read_nonblock: (int len, ?string buf, ?exception: bool) -> String? + def read_nonblock: (int len, ?string? buf, ?exception: bool) -> String? def readbyte: () -> Integer @@ -1311,7 +1311,7 @@ class StringIO # def readlines: (?String sep, ?Integer limit, ?chomp: boolish) -> ::Array[String] - def readpartial: (int maxlen, ?string outbuf) -> String + def readpartial: (int maxlen, ?string? outbuf) -> String # # See Zlib::GzipReader documentation for a description. # - def read: (?int? length, ?string outbuf) -> String? + def read: (?int? length, ?string? outbuf) -> String? #