'failed to produce diagnostic for expression, Xcode 11.4, Moya
After updating to Xcode 11.4, I started to get this error
Failed to produce diagnostic for expression please file a bug report
On:
let provider = MoyaProvider<EndPoint>(requestClosure: requestClosure)
I updated Moya but it doesn't look like the issue. Runs fine on previous Xcode versions.
full code:
let requestClosure: MoyaProvider.RequestClosure = {
[unowned self] (endpoint: Endpoint, done: @escaping MoyaProvider.RequestResultClosure) in
guard let request = try? endpoint.urlRequest() else { return }
self.authenticator.authenticate(request, done: { (request) in
done(.success(request))
})
}
provider = MoyaProvider<EndPoint>(requestClosure: requestClosure
Solution 1:[1]
I found the issue, Xcode 11.4 compile issues are not verbose enough when it comes to optionals
and generics
.
Moya version and Swift
version were not changed.
An issue with generics:
let requestClosure: MoyaProvider<EndPoint>.RequestClosure
Had to explicitly define the type in the closure, which makes sense, but was not a requirement pre-Xcode version 11.4
let requestClosure: MoyaProvider<EndPoint>.RequestClosure = {
[unowned self] (endpoint: Endpoint, done: @escaping MoyaProvider.RequestResultClosure) in
guard let request = try? endpoint.urlRequest() else { return }
self.authenticator.authenticate(request, done: { (request) in
done(.success(request))
})
}
provider = MoyaProvider<EndPoint>(requestClosure: requestClosure
Solution 2:[2]
For me the I was getting that error because one of my property was of type Error and I was assigning a value of type LocalizedError to it. Changing the property type to LocalizedError fixed the problem.
Solution 3:[3]
It seems to be an Xcode bug for some cases at least. I renamed a protocol and then renamed it back and the issue was gone.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tal Zion |
Solution 2 | EasySkankin |
Solution 3 | Abdurrahman Mubeen Ali |