Skip to content

Commit

Permalink
Fix or revert some return type restrictions from #10575 (#10857)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Jul 3, 2021
1 parent 7be467c commit 7e94d52
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/digest/io_digest.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class IO::Digest < IO
end

def read(slice : Bytes) : Int32
read_bytes = io.read(slice)
read_bytes = io.read(slice).to_i32
if @mode.read?
digest_algorithm.update(slice[0, read_bytes])
end
Expand Down
6 changes: 3 additions & 3 deletions src/enumerable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ module Enumerable(T)
# ```
# [1, 2, 3, 4].count { |i| i % 2 == 0 } # => 2
# ```
def count
def count(& : T -> _) : Int32
count = 0
each { |e| count += 1 if yield e }
count
Expand Down Expand Up @@ -624,7 +624,7 @@ module Enumerable(T)
# ```
#
# Returns `nil` if the block didn't return `true` for any element.
def index
def index(& : T -> _) : Int32?
each_with_index do |e, i|
return i if yield e
end
Expand All @@ -638,7 +638,7 @@ module Enumerable(T)
# ```
#
# Returns `nil` if *obj* is not in the collection.
def index(obj)
def index(obj) : Int32?
index { |e| e == obj }
end

Expand Down
8 changes: 4 additions & 4 deletions src/http/content.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module HTTP

def read(slice : Bytes) : Int32
ensure_send_continue
@io.read(slice)
@io.read(slice).to_i32
end

def read_byte : UInt8?
Expand All @@ -73,7 +73,7 @@ module HTTP
@io.peek
end

def skip(bytes_count) : Int32?
def skip(bytes_count) : Nil
ensure_send_continue
@io.skip(bytes_count)
end
Expand Down Expand Up @@ -123,7 +123,7 @@ module HTTP

to_read = Math.min(count, @chunk_remaining)

bytes_read = @io.read slice[0, to_read]
bytes_read = @io.read(slice[0, to_read]).to_i32

if bytes_read == 0
raise IO::EOFError.new("Invalid HTTP chunked content")
Expand Down Expand Up @@ -164,7 +164,7 @@ module HTTP
peek
end

def skip(bytes_count) : Int32?
def skip(bytes_count) : Nil
ensure_send_continue
if bytes_count <= @chunk_remaining
@io.skip(bytes_count)
Expand Down
2 changes: 1 addition & 1 deletion src/humanize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct Number
end

# :nodoc:
def self.prefix_index(i, group = 3) : Int32
def self.prefix_index(i : Int32, group : Int32 = 3) : Int32
((i - (i > 0 ? 1 : 0)) // group) * group
end

Expand Down
4 changes: 2 additions & 2 deletions src/io/hexdump.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class IO::Hexdump < IO
def initialize(@io : IO, @output : IO = STDERR, @read = false, @write = false)
end

def read(buf : Bytes)
@io.read(buf).tap do |read_bytes|
def read(buf : Bytes) : Int32
@io.read(buf).to_i32.tap do |read_bytes|
buf[0, read_bytes].hexdump(@output) if @read && read_bytes
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/io/memory.cr
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class IO::Memory < IO
end

# :nodoc:
def skip(bytes_count)
def skip(bytes_count) : Nil
check_open

available = @bytesize - @pos
Expand Down
2 changes: 1 addition & 1 deletion src/io/sized.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IO::Sized < IO
check_open

count = {slice.size.to_u64, @read_remaining}.min
bytes_read = @io.read slice[0, count]
bytes_read = @io.read(slice[0, count]).to_i32
@read_remaining -= bytes_read
bytes_read
end
Expand Down
2 changes: 1 addition & 1 deletion src/io/stapled.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IO::Stapled < IO
def read(slice : Bytes) : Int32
check_open

@reader.read(slice)
@reader.read(slice).to_i32
end

# Gets a string from `reader`.
Expand Down
4 changes: 2 additions & 2 deletions src/string.cr
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class String
# s[-2..-4] # => ""
# s[-2..1] # => ""
# s[3..-4] # => ""
# ``` : String
# ```
def [](range : Range) : String
self[*Indexable.range_to_index_and_count(range, size) || raise IndexError.new]
end
Expand Down Expand Up @@ -5010,7 +5010,7 @@ class String
# Raises an `ArgumentError` if `self` has null bytes. Returns `self` otherwise.
#
# This method should sometimes be called before passing a `String` to a C function.
def check_no_null_byte(name = nil) : String
def check_no_null_byte(name = nil) : self
if byte_index(0)
name = "`#{name}` " if name
raise ArgumentError.new("String #{name}contains null byte")
Expand Down

0 comments on commit 7e94d52

Please sign in to comment.