Skip to content

Commit

Permalink
Fix existential-any for Swift6 (Alamofire#3881)
Browse files Browse the repository at this point in the history
### Goals ⚽
Resolve `existential-any` build errors.

### Implementation Details 🚧

Added `any` to each protocols.  

https://github.com/swiftlang/swift-evolution/blob/main/proposals/0335-existential-any.md

Co-authored-by: Jon Shier <[email protected]>
  • Loading branch information
kitwtnb and jshier authored Sep 14, 2024
1 parent 17c7f9b commit 5716278
Show file tree
Hide file tree
Showing 45 changed files with 535 additions and 535 deletions.
58 changes: 29 additions & 29 deletions Source/Core/AFError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public enum AFError: Error {
/// The file at the `fileURL` provided was not reachable.
case bodyPartFileNotReachable(at: URL)
/// Attempting to check the reachability of the `fileURL` provided threw an error.
case bodyPartFileNotReachableWithError(atURL: URL, error: Error)
case bodyPartFileNotReachableWithError(atURL: URL, error: any Error)
/// The file at the `fileURL` provided is actually a directory.
case bodyPartFileIsDirectory(at: URL)
/// The size of the file at the `fileURL` provided was not returned by the system.
case bodyPartFileSizeNotAvailable(at: URL)
/// The attempt to find the size of the file at the `fileURL` provided threw an error.
case bodyPartFileSizeQueryFailedWithError(forURL: URL, error: Error)
case bodyPartFileSizeQueryFailedWithError(forURL: URL, error: any Error)
/// An `InputStream` could not be created for the provided `fileURL`.
case bodyPartInputStreamCreationFailed(for: URL)
/// An `OutputStream` could not be created when attempting to write the encoded data to disk.
Expand All @@ -56,9 +56,9 @@ public enum AFError: Error {
/// The `fileURL` provided for writing the encoded body data to disk is not a file `URL`.
case outputStreamURLInvalid(url: URL)
/// The attempt to write the encoded body data to disk failed with an underlying error.
case outputStreamWriteFailed(error: Error)
case outputStreamWriteFailed(error: any Error)
/// The attempt to read an encoded body part `InputStream` failed with underlying system error.
case inputStreamReadFailed(error: Error)
case inputStreamReadFailed(error: any Error)
}

/// Represents unexpected input stream length that occur when encoding the `MultipartFormData`. Instances will be
Expand All @@ -75,9 +75,9 @@ public enum AFError: Error {
/// The `URLRequest` did not have a `URL` to encode.
case missingURL
/// JSON serialization failed with an underlying system error during the encoding process.
case jsonEncodingFailed(error: Error)
case jsonEncodingFailed(error: any Error)
/// Custom parameter encoding failed due to the associated `Error`.
case customEncodingFailed(error: Error)
case customEncodingFailed(error: any Error)
}

/// The underlying reason the `.parameterEncoderFailed` error occurred.
Expand All @@ -93,7 +93,7 @@ public enum AFError: Error {
/// A `RequiredComponent` was missing during encoding.
case missingRequiredComponent(RequiredComponent)
/// The underlying encoder failed with the associated error.
case encoderFailed(error: Error)
case encoderFailed(error: any Error)
}

/// The underlying reason the `.responseValidationFailed` error occurred.
Expand All @@ -110,7 +110,7 @@ public enum AFError: Error {
/// The response status code was not acceptable.
case unacceptableStatusCode(code: Int)
/// Custom response validation failed due to the associated `Error`.
case customValidationFailed(error: Error)
case customValidationFailed(error: any Error)
}

/// The underlying reason the response serialization error occurred.
Expand All @@ -124,11 +124,11 @@ public enum AFError: Error {
/// String serialization failed using the provided `String.Encoding`.
case stringSerializationFailed(encoding: String.Encoding)
/// JSON serialization failed with an underlying system error.
case jsonSerializationFailed(error: Error)
case jsonSerializationFailed(error: any Error)
/// A `DataDecoder` failed to decode the response due to the associated `Error`.
case decodingFailed(error: Error)
case decodingFailed(error: any Error)
/// A custom response serializer failed due to the associated `Error`.
case customSerializationFailed(error: Error)
case customSerializationFailed(error: any Error)
/// Generic serialization failed for an empty response that wasn't type `Empty` but instead the associated type.
case invalidEmptyResponse(type: String)
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public enum AFError: Error {
/// During evaluation, creation of the revocation policy failed.
case revocationPolicyCreationFailed
/// `SecTrust` evaluation failed with the associated `Error`, if one was produced.
case trustEvaluationFailed(error: Error?)
case trustEvaluationFailed(error: (any Error)?)
/// Default evaluation failed with the associated `Output`.
case defaultEvaluationFailed(output: Output)
/// Host validation failed with the associated `Output`.
Expand All @@ -181,7 +181,7 @@ public enum AFError: Error {
/// Public key pinning failed.
case publicKeyPinningFailed(host: String, trust: SecTrust, pinnedKeys: [SecKey], serverKeys: [SecKey])
/// Custom server trust evaluation failed due to the associated `Error`.
case customEvaluationFailed(error: Error)
case customEvaluationFailed(error: any Error)
}
#endif

Expand All @@ -192,25 +192,25 @@ public enum AFError: Error {
}

/// `UploadableConvertible` threw an error in `createUploadable()`.
case createUploadableFailed(error: Error)
case createUploadableFailed(error: any Error)
/// `URLRequestConvertible` threw an error in `asURLRequest()`.
case createURLRequestFailed(error: Error)
case createURLRequestFailed(error: any Error)
/// `SessionDelegate` threw an error while attempting to move downloaded file to destination URL.
case downloadedFileMoveFailed(error: Error, source: URL, destination: URL)
case downloadedFileMoveFailed(error: any Error, source: URL, destination: URL)
/// `Request` was explicitly cancelled.
case explicitlyCancelled
/// `URLConvertible` type failed to create a valid `URL`.
case invalidURL(url: URLConvertible)
case invalidURL(url: any URLConvertible)
/// Multipart form encoding failed.
case multipartEncodingFailed(reason: MultipartEncodingFailureReason)
/// `ParameterEncoding` threw an error during the encoding process.
case parameterEncodingFailed(reason: ParameterEncodingFailureReason)
/// `ParameterEncoder` threw an error while running the encoder.
case parameterEncoderFailed(reason: ParameterEncoderFailureReason)
/// `RequestAdapter` threw an error during adaptation.
case requestAdaptationFailed(error: Error)
case requestAdaptationFailed(error: any Error)
/// `RequestRetrier` threw an error during the request retry process.
case requestRetryFailed(retryError: Error, originalError: Error)
case requestRetryFailed(retryError: any Error, originalError: any Error)
/// Response validation failed.
case responseValidationFailed(reason: ResponseValidationFailureReason)
/// Response serialization failed.
Expand All @@ -222,9 +222,9 @@ public enum AFError: Error {
/// `Session` which issued the `Request` was deinitialized, most likely because its reference went out of scope.
case sessionDeinitialized
/// `Session` was explicitly invalidated, possibly with the `Error` produced by the underlying `URLSession`.
case sessionInvalidated(error: Error?)
case sessionInvalidated(error: (any Error)?)
/// `URLSessionTask` completed with error.
case sessionTaskFailed(error: Error)
case sessionTaskFailed(error: any Error)
/// `URLRequest` failed validation.
case urlRequestValidationFailed(reason: URLRequestValidationFailureReason)
}
Expand Down Expand Up @@ -367,7 +367,7 @@ extension AFError {

extension AFError {
/// The `URLConvertible` associated with the error.
public var urlConvertible: URLConvertible? {
public var urlConvertible: (any URLConvertible)? {
guard case let .invalidURL(url) = self else { return nil }
return url
}
Expand All @@ -381,7 +381,7 @@ extension AFError {
/// The underlying `Error` responsible for generating the failure associated with `.sessionInvalidated`,
/// `.parameterEncodingFailed`, `.parameterEncoderFailed`, `.multipartEncodingFailed`, `.requestAdaptationFailed`,
/// `.responseSerializationFailed`, `.requestRetryFailed` errors.
public var underlyingError: Error? {
public var underlyingError: (any Error)? {
switch self {
case let .multipartEncodingFailed(reason):
return reason.underlyingError
Expand Down Expand Up @@ -464,7 +464,7 @@ extension AFError {
}

extension AFError.ParameterEncodingFailureReason {
var underlyingError: Error? {
var underlyingError: (any Error)? {
switch self {
case let .jsonEncodingFailed(error),
let .customEncodingFailed(error):
Expand All @@ -476,7 +476,7 @@ extension AFError.ParameterEncodingFailureReason {
}

extension AFError.ParameterEncoderFailureReason {
var underlyingError: Error? {
var underlyingError: (any Error)? {
switch self {
case let .encoderFailed(error):
return error
Expand Down Expand Up @@ -507,7 +507,7 @@ extension AFError.MultipartEncodingFailureReason {
}
}

var underlyingError: Error? {
var underlyingError: (any Error)? {
switch self {
case let .bodyPartFileNotReachableWithError(_, error),
let .bodyPartFileSizeQueryFailedWithError(_, error),
Expand Down Expand Up @@ -568,7 +568,7 @@ extension AFError.ResponseValidationFailureReason {
}
}

var underlyingError: Error? {
var underlyingError: (any Error)? {
switch self {
case let .customValidationFailed(error):
return error
Expand Down Expand Up @@ -598,7 +598,7 @@ extension AFError.ResponseSerializationFailureReason {
}
}

var underlyingError: Error? {
var underlyingError: (any Error)? {
switch self {
case let .jsonSerializationFailed(error),
let .decodingFailed(error),
Expand Down Expand Up @@ -636,7 +636,7 @@ extension AFError.ServerTrustFailureReason {
}
}

var underlyingError: Error? {
var underlyingError: (any Error)? {
switch self {
case let .customEvaluationFailed(error):
return error
Expand Down
20 changes: 10 additions & 10 deletions Source/Core/DataRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Foundation
/// `Request` subclass which handles in-memory `Data` download using `URLSessionDataTask`.
public class DataRequest: Request {
/// `URLRequestConvertible` value used to create `URLRequest`s for this instance.
public let convertible: URLRequestConvertible
public let convertible: any URLRequestConvertible
/// `Data` read from the server so far.
public var data: Data? { dataMutableState.data }

Expand All @@ -52,12 +52,12 @@ public class DataRequest: Request {
/// - interceptor: `RequestInterceptor` used throughout the request lifecycle.
/// - delegate: `RequestDelegate` that provides an interface to actions not performed by the `Request`.
init(id: UUID = UUID(),
convertible: URLRequestConvertible,
convertible: any URLRequestConvertible,
underlyingQueue: DispatchQueue,
serializationQueue: DispatchQueue,
eventMonitor: EventMonitor?,
interceptor: RequestInterceptor?,
delegate: RequestDelegate) {
eventMonitor: (any EventMonitor)?,
interceptor: (any RequestInterceptor)?,
delegate: any RequestDelegate) {
self.convertible = convertible

super.init(id: id,
Expand Down Expand Up @@ -349,7 +349,7 @@ public class DataRequest: Request {
/// - Returns: The request.
@discardableResult
public func responseData(queue: DispatchQueue = .main,
dataPreprocessor: DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor,
dataPreprocessor: any DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor,
emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods,
completionHandler: @escaping (AFDataResponse<Data>) -> Void) -> Self {
Expand All @@ -375,7 +375,7 @@ public class DataRequest: Request {
/// - Returns: The request.
@discardableResult
public func responseString(queue: DispatchQueue = .main,
dataPreprocessor: DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor,
dataPreprocessor: any DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor,
encoding: String.Encoding? = nil,
emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods,
Expand Down Expand Up @@ -404,7 +404,7 @@ public class DataRequest: Request {
@available(*, deprecated, message: "responseJSON deprecated and will be removed in Alamofire 6. Use responseDecodable instead.")
@discardableResult
public func responseJSON(queue: DispatchQueue = .main,
dataPreprocessor: DataPreprocessor = JSONResponseSerializer.defaultDataPreprocessor,
dataPreprocessor: any DataPreprocessor = JSONResponseSerializer.defaultDataPreprocessor,
emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods,
options: JSONSerialization.ReadingOptions = .allowFragments,
Expand Down Expand Up @@ -433,8 +433,8 @@ public class DataRequest: Request {
@discardableResult
public func responseDecodable<T: Decodable>(of type: T.Type = T.self,
queue: DispatchQueue = .main,
dataPreprocessor: DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor,
decoder: DataDecoder = JSONDecoder(),
dataPreprocessor: any DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor,
decoder: any DataDecoder = JSONDecoder(),
emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods,
completionHandler: @escaping (AFDataResponse<T>) -> Void) -> Self {
Expand Down
24 changes: 12 additions & 12 deletions Source/Core/DataStreamRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public final class DataStreamRequest: Request {
}

/// `URLRequestConvertible` value used to create `URLRequest`s for this instance.
public let convertible: URLRequestConvertible
public let convertible: any URLRequestConvertible
/// Whether or not the instance will be cancelled if stream parsing encounters an error.
public let automaticallyCancelOnStreamError: Bool

Expand Down Expand Up @@ -122,13 +122,13 @@ public final class DataStreamRequest: Request {
/// - delegate: `RequestDelegate` that provides an interface to actions not performed by
/// the `Request`.
init(id: UUID = UUID(),
convertible: URLRequestConvertible,
convertible: any URLRequestConvertible,
automaticallyCancelOnStreamError: Bool,
underlyingQueue: DispatchQueue,
serializationQueue: DispatchQueue,
eventMonitor: EventMonitor?,
interceptor: RequestInterceptor?,
delegate: RequestDelegate) {
eventMonitor: (any EventMonitor)?,
interceptor: (any RequestInterceptor)?,
delegate: any RequestDelegate) {
self.convertible = convertible
self.automaticallyCancelOnStreamError = automaticallyCancelOnStreamError

Expand Down Expand Up @@ -460,8 +460,8 @@ public final class DataStreamRequest: Request {
@discardableResult
public func responseStreamDecodable<T: Decodable>(of type: T.Type = T.self,
on queue: DispatchQueue = .main,
using decoder: DataDecoder = JSONDecoder(),
preprocessor: DataPreprocessor = PassthroughPreprocessor(),
using decoder: any DataDecoder = JSONDecoder(),
preprocessor: any DataPreprocessor = PassthroughPreprocessor(),
stream: @escaping Handler<T, AFError>) -> Self {
responseStream(using: DecodableStreamSerializer<T>(decoder: decoder, dataPreprocessor: preprocessor),
on: queue,
Expand Down Expand Up @@ -517,16 +517,16 @@ public protocol DataStreamSerializer {
/// `DataStreamSerializer` which uses the provided `DataPreprocessor` and `DataDecoder` to serialize the incoming `Data`.
public struct DecodableStreamSerializer<T: Decodable>: DataStreamSerializer {
/// `DataDecoder` used to decode incoming `Data`.
public let decoder: DataDecoder
public let decoder: any DataDecoder
/// `DataPreprocessor` incoming `Data` is passed through before being passed to the `DataDecoder`.
public let dataPreprocessor: DataPreprocessor
public let dataPreprocessor: any DataPreprocessor

/// Creates an instance with the provided `DataDecoder` and `DataPreprocessor`.
/// - Parameters:
/// - decoder: ` DataDecoder` used to decode incoming `Data`. `JSONDecoder()` by default.
/// - dataPreprocessor: `DataPreprocessor` used to process incoming `Data` before it's passed through the
/// `decoder`. `PassthroughPreprocessor()` by default.
public init(decoder: DataDecoder = JSONDecoder(), dataPreprocessor: DataPreprocessor = PassthroughPreprocessor()) {
public init(decoder: any DataDecoder = JSONDecoder(), dataPreprocessor: any DataPreprocessor = PassthroughPreprocessor()) {
self.decoder = decoder
self.dataPreprocessor = dataPreprocessor
}
Expand Down Expand Up @@ -568,8 +568,8 @@ extension DataStreamSerializer {
/// - dataPreprocessor: `DataPreprocessor` used to process incoming `Data` before it's passed through the
/// `decoder`. `PassthroughPreprocessor()` by default.
public static func decodable<T: Decodable>(of type: T.Type,
decoder: DataDecoder = JSONDecoder(),
dataPreprocessor: DataPreprocessor = PassthroughPreprocessor()) -> Self where Self == DecodableStreamSerializer<T> {
decoder: any DataDecoder = JSONDecoder(),
dataPreprocessor: any DataPreprocessor = PassthroughPreprocessor()) -> Self where Self == DecodableStreamSerializer<T> {
DecodableStreamSerializer<T>(decoder: decoder, dataPreprocessor: dataPreprocessor)
}
}
Expand Down
Loading

0 comments on commit 5716278

Please sign in to comment.