Skip to content

Commit

Permalink
Fix return type restrictions crystal-lang#10583
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jun 28, 2021
1 parent 7331f5b commit 334e49e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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
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 334e49e

Please sign in to comment.