google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.
Apache License 2.0
3.79k stars 292 forks source link

Contextual type for closure argument list expects 2 arguments, which cannot be implicitly ignored #132

Closed akellyak47 closed 4 years ago

akellyak47 commented 4 years ago

Hello,

I'm experiencing some peculiar compiler-related issues.

This example compiles/runs as expected:

        Promise<PlaceDetailResponse>(on: .global()) {
            return try await(GoogleMapsHTTPClient.getPlaceDetails(placeID: placeID))
        }.then {
            print($0.name)
        }

However, if I insert any code (e.g. a print statement) above the above return my code fails to compile with the following error: "Contextual type for closure argument list expects 2 arguments, which cannot be implicitly ignored"

If I take Xcode's suggestion of adding _,_ in I get a new error message: "Unexpected non-void return value in void function"

Am I missing something obvious here?

shoumikhin commented 4 years ago

Hi @akellyak47,

Please try the following:

Promise(on: .global()) { () -> PlaceDetailResponse in
  print("hello")
  return try await(GoogleMapsHTTPClient.getPlaceDetails(placeID: placeID))
}.then {
  print($0.name)
}
akellyak47 commented 4 years ago

Hey @shoumikhin,

Thanks for the response. That worked like a charm. As a note, I had to specify <PlaceDetailResponse> after Promise to remove the following error: "Ambiguous reference to member 'then(on:_:)'". I'm guessing that's a shortcoming with Swift's type inference.