Skip to content
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

Merged
merged 2 commits into from
May 15, 2017

Conversation

ikesyo
Copy link
Member

@ikesyo ikesyo commented May 15, 2017

Originally reported in mdiep/Tentacle#66.

@@ -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 {
Copy link
Contributor

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?)

Copy link
Member Author

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:

Result/Result/Result.swift

Lines 183 to 187 in 65d0c81

if let anyError = error as? AnyError {
self = anyError
} else {
self.error = error
}

Copy link
Contributor

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 {
Copy link
Contributor

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.

@ikesyo
Copy link
Member Author

ikesyo commented May 15, 2017

Thanks for the review! 🚢

@ikesyo ikesyo merged commit c342be6 into master May 15, 2017
@ikesyo ikesyo deleted the init-attempt-improve-anyerror-support branch May 15, 2017 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants