I have 3 functions with same name but different signatures defined as following
// 1
func send<T: Decodable>(_ request: HTTPSClient.Request) async throws -> T {
...
}
// 2
func send(_ request: HTTPSClient.Request) async throws -> Data {
...
}
// 3
func send(_ request: HTTPSClient.Request) async throws {
...
}
Now when trying to call these
// Works fine, SomeResponse is Codable
let response: SomeResponse = try await self.send(httpsRequest)
// Works fine
let response: Data = try await self.send(httpsRequest)
// Does not work
try await self.send(httpsRequest)
The 1st and 2nd declarations are accessible as expected but on the 3rd one I get error Ambiguous use of 'send'
with 2nd and 3rd declarations as possible candidates.
According to my understanding this shouldn't happen since the 3rd call does not expect a return so it should call 3rd declaration. What am I missing here?
Note declaration 2 does not have
@discardableResult
CodePudding user response:
You need to tell the compiler what the return type is so change the call to
try await self.send(httpsRequest) as Void
See this blog post from the Apple Developer site