diff --git a/.swift-version b/.swift-version index 1fc762a..d54e0b2 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0-PREVIEW-2 +3.0-PREVIEW-4 diff --git a/Result/Result.swift b/Result/Result.swift index 5ab9c48..842fc94 100644 --- a/Result/Result.swift +++ b/Result/Result.swift @@ -1,7 +1,7 @@ // Copyright (c) 2015 Rob Rix. All rights reserved. /// An enum representing either a failure with an explanatory error, or a success with a result value. -public enum Result: ResultProtocol, CustomStringConvertible, CustomDebugStringConvertible { +public enum Result: ResultProtocol, CustomStringConvertible, CustomDebugStringConvertible { case success(T) case failure(Error) @@ -157,8 +157,8 @@ public func `try`(_ function: String = #function, file: String = #file, line: In // MARK: - ErrorProtocolConvertible conformance extension NSError: ErrorProtocolConvertible { - public static func error(from error: ErrorProtocol) -> Self { - func cast(_ error: ErrorProtocol) -> T { + public static func error(from error: Swift.Error) -> Self { + func cast(_ error: Swift.Error) -> T { return error as! T } @@ -173,7 +173,7 @@ extension NSError: ErrorProtocolConvertible { /// This can be used to describe `Result`s where failures will never /// be generated. For example, `Result` describes a result that /// contains an `Int`eger and is guaranteed never to be a `Failure`. -public enum NoError: ErrorProtocol { } +public enum NoError: Swift.Error { } // MARK: - migration support extension Result { @@ -190,7 +190,7 @@ extension Result { extension NSError { @available(*, unavailable, renamed: "error(from:)") - public static func errorFromErrorType(_ error: ErrorProtocol) -> Self { + public static func errorFromErrorType(_ error: Swift.Error) -> Self { fatalError() } } diff --git a/Result/ResultProtocol.swift b/Result/ResultProtocol.swift index f4b0d28..ae33ffd 100644 --- a/Result/ResultProtocol.swift +++ b/Result/ResultProtocol.swift @@ -3,7 +3,7 @@ /// A type that can represent either failure with an error or success with a result value. public protocol ResultProtocol { associatedtype Value - associatedtype Error: ErrorProtocol + associatedtype Error: Swift.Error /// Constructs a successful result wrapping a `value`. init(value: Value) @@ -82,8 +82,8 @@ public extension ResultProtocol { } /// Protocol used to constrain `tryMap` to `Result`s with compatible `Error`s. -public protocol ErrorProtocolConvertible: ErrorProtocol { - static func error(from error: ErrorProtocol) -> Self +public protocol ErrorProtocolConvertible: Swift.Error { + static func error(from error: Swift.Error) -> Self } public extension ResultProtocol where Error: ErrorProtocolConvertible { @@ -135,9 +135,9 @@ public func >>- (result: T, transform: @noescape (T.Value /// Returns `true` if `left` and `right` are both `Success`es and their values are equal, or if `left` and `right` are both `Failure`s and their errors are equal. public func == (left: T, right: T) -> Bool { - if let left = left.value, right = right.value { + if let left = left.value, let right = right.value { return left == right - } else if let left = left.error, right = right.error { + } else if let left = left.error, let right = right.error { return left == right } return false @@ -163,7 +163,7 @@ public func ?? (left: T, right: @autoclosure () -> T) -> T { public typealias ResultType = ResultProtocol @available(*, unavailable, renamed: "ErrorProtocol") -public typealias ResultErrorType = ErrorProtocol +public typealias ResultErrorType = Swift.Error @available(*, unavailable, renamed: "ErrorProtocolConvertible") public typealias ErrorTypeConvertible = ErrorProtocolConvertible @@ -177,7 +177,7 @@ extension ResultProtocol { extension ErrorProtocolConvertible { @available(*, unavailable, renamed: "error(from:)") - public static func errorFromErrorType(_ error: ErrorProtocol) -> Self { + public static func errorFromErrorType(_ error: Swift.Error) -> Self { fatalError() } } diff --git a/Tests/Result/ResultTests.swift b/Tests/Result/ResultTests.swift index 2989f9d..071f980 100644 --- a/Tests/Result/ResultTests.swift +++ b/Tests/Result/ResultTests.swift @@ -100,7 +100,7 @@ final class ResultTests: XCTestCase { } func testRecoverProducesRightForLeftFailure() { - struct Error: ErrorProtocol {} + struct Error: Swift.Error {} let left = Result.failure(Error()) XCTAssertEqual(left.recover("right"), "right") @@ -116,7 +116,7 @@ final class ResultTests: XCTestCase { } func testRecoverWithProducesRightSuccessForLeftFailureAndRightSuccess() { - struct Error: ErrorProtocol {} + struct Error: Swift.Error {} let left = Result.failure(Error()) let right = Result.success("right") @@ -125,7 +125,7 @@ final class ResultTests: XCTestCase { } func testRecoverWithProducesRightFailureForLeftFailureAndRightFailure() { - enum Error: ErrorProtocol { case left, right } + enum Error: Swift.Error { case left, right } let left = Result.failure(.left) let right = Result.failure(.right) @@ -220,7 +220,7 @@ func attempt(_ value: T, succeed: Bool, error: NSErrorPointer) -> T? { #endif func tryIsSuccess(_ text: String?) throws -> String { - guard let text = text where text == "success" else { + guard let text = text, text == "success" else { throw error }