Swift 6 warning: No async
operations occur
#227
-
I'm auditing an app for Swift 6 support, and I ran into warnings in a TCA dependency while using let isolated = ActorIsolated([Int: String]())
let s = await isolated.value[0] So far, so good. Now I introduce a simple dependency and initialize it using an inline struct Client: Sendable {
var key: @Sendable (Int) async throws -> String
}
let client: Client = {
let isolated = ActorIsolated([Int: String]())
return Client { key in
await isolated.value[key] ?? ""
}
}() Again, no problem. But when I add it as a extension Client: DependencyKey {
static let liveValue: Client = {
let isolated = ActorIsolated([Int: String]())
return Client { key in
await isolated.value[key] ?? ""
// 👆 No 'async' operations occur within 'await' expression
}
}()
} I can't see anything in the declaration of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@seanmrich This looks like a Swift bug. I can reproduce outside of swift-dependencies and mainly seems to be the static let f: @Sendable () async -> Int = {
actor A { var p = 0 }
return await A().p
} Want to file a bug with Apple and ask what the expected behavior is? In your case you can change to a computed |
Beta Was this translation helpful? Give feedback.
@seanmrich This looks like a Swift bug. I can reproduce outside of swift-dependencies and mainly seems to be the static
let
assignment:Want to file a bug with Apple and ask what the expected behavior is?
In your case you can change to a computed
static var
to fix. But I'd also suggest not usingActorIsolated
. We think thatLockIsolated
should almost always be preferred, and are having enough of a hard time motivatingActorIsolated
that we will probably deprecate it soon.