-
Notifications
You must be signed in to change notification settings - Fork 227
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
Improve AnyError support in Result.init(attempt:)
#223
Conversation
@@ -31,7 +31,10 @@ public enum Result<T, Error: Swift.Error>: ResultProtocol, CustomStringConvertib | |||
public init(attempt f: () throws -> T) { | |||
do { | |||
self = .success(try f()) | |||
} catch { | |||
} catch var error { | |||
if Error.self == AnyError.self { |
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.
This should probably only be if error
isn't an AnyError
? (Can you add a test for that?)
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.
I think that is already covered here:
Lines 183 to 187 in 65d0c81
if let anyError = error as? AnyError { | |
self = anyError | |
} else { | |
self.error = error | |
} |
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.
👍
I didn't realize that.
@@ -31,7 +31,10 @@ public enum Result<T, Error: Swift.Error>: ResultProtocol, CustomStringConvertib | |||
public init(attempt f: () throws -> T) { | |||
do { | |||
self = .success(try f()) | |||
} catch { | |||
} catch var error { | |||
if Error.self == AnyError.self { |
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.
👍
I didn't realize that.
Thanks for the review! 🚢 |
Originally reported in mdiep/Tentacle#66.