How the compiler converts dataTask completion handler to async return when both data and error are nil?

Now and then I wonder if the completion handler for dataTask can ever return data, response and error all nil at the same time and I'm thinking about this again because the async version of it always returns a tuple of non nil data and response values. So, can this case ever happen? If yes does the compiler create a new error (John Sundell does this in AsyncCompatibilityKit) or returns an empty Data() and URLResponse()? If no the compiler just force unwrapa data and response?
@Douglas_Gregor I saw that you are the author of Concurrency Interoperability with Objective-C so I would be really grateful if you could answer how the interoperability is done for dataTask. I couldn't find the answer for this specific case in the proposal, sorry if it's there.

I believe URLSession guarantees an error if no response is received. This was discussed a few years ago during the Result proposal (I think it was that proposal) and we got that confirmation. Of course, a response without data means empty Data in the response.

As for this particular API, the async URLSession APIs are not automatically adapted from the completion handler APIs on URLSession, likely due to the considerations you mentioned. These appear to be brand new APIs that improve upon the existing ones through the addition of the delegate parameter.

1 Like