connectrpc/connect-swift

`ConnectError.unpackedDetails` Swift 6 Compatibility

Closed this issue · 0 comments

eseay commented

I have a helper extension in one up my packages that depends on Connect-Swift that is defined as follows:

func unpackFirst<M: SwiftProtobuf.Message>(_ messageType: M.Type) -> M? {
    unpackedDetails().first
}

...which is used in a manner similar to what's described in the doc comment for ConnectError.unpackedDetails:

let myMessage = error.unpackFirst(SomeMessageType.self).

I am working on migrating my package to support Swift 6, and when building with Xcode 16.1 and compiling with Swift 6, I am receiving the following error in my function's implementation

unpackedDetails().first -> "Type of expression is ambiguous without a type annotation".

I have been able to resolve the issue by adjusting my function implementation as follows:

func unpackFirst<M: SwiftProtobuf.Message>(_ messageType: M.Type) -> M? {
#if swift(>=6.0)
    let details: [M] = unpackedDetails()
    return details.first
#else
    return unpackedDetails().first
#endif
}