-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix or revert some return type restrictions from #10575 #10857
Changes from 6 commits
7331f5b
334e49e
0cad8f7
b7a7cc2
fa23fb5
b998a9f
e8cf88e
68b9575
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -638,7 +638,7 @@ module Enumerable(T) | |
# ``` | ||
# | ||
# Returns `nil` if *obj* is not in the collection. | ||
def index(obj) | ||
def index(obj) : Int32? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #10582 added a return type restriction |
||
index { |e| e == obj } | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ class IO::ARGF < IO | |
@read_from_stdin = false | ||
end | ||
|
||
def read(slice : Bytes) : Int32 | ||
def read(slice : Bytes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually not necessary anymore because of #10828 which already added a type cast to We should either remove all restrictions (i.e. revert #10828) or cast all return types to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also turn these restrictions into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oprypin IIRC u can't do this for the return type restrictions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any value in that. Either we remove the potentially erroneous restrictions again or make them true. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm convinced we should have the restriction and cast to Question is only if we do that for 1.1 or 1.2. Technically, it's okay because the restrictions are already in place and the change to make sure they hold under all circumstances is a bug fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm I see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're set on Int32 in many places, so I don't think this is really much of an issue. |
||
first_initialize unless @initialized | ||
|
||
if current_io = @current_io | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ class IO::Sized < IO | |
@read_remaining = read_size.to_u64 | ||
end | ||
|
||
def read(slice : Bytes) : Int32 | ||
def read(slice : Bytes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can confirm this annotation was causing an issue as well. |
||
check_open | ||
|
||
count = {slice.size.to_u64, @read_remaining}.min | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The non-yielding overload (right below) received a
Int32
return type restriction in #10582. But this restriction only holds if the yielding overload returnsInt32
as well (which is in fact the case). So I figured we should just add it for consistency.(The block type annotation is an extra, but it's directly derived from
#each
.)