Is there any guidance on how to deal with concurrency warnings? #2847
-
If you set concurrency warnings to full, a lot of warnings start creeping up. My Package definition contains the following setup: for target in package.targets where target.type != .system {
target.swiftSettings = target.swiftSettings ?? []
target.swiftSettings?.append(
.unsafeFlags([
"-Xfrontend", "-warn-concurrency",
"-Xfrontend", "-enable-actor-data-race-checks",
])
)
} I noticed that having set that, warnings like Cannot form key path that captures non-sendable type 'KeyPath<AppFeature.Action.AllCasePaths, AnyCasePath<AppFeature.Action, Feature.Action>>' start showing up a lot with the newest version of the Composable Architecture. I checked all my model types and added Two places stuck out the most, namely the static properties of dependencies required by Static property 'testValue' is not concurrency-safe because it is non-isolated global shared mutable state; this is an error in Swift 6 and the usage of said dependency within the reducer itself which results in await send(.taskResponse(Result { try await self.client.fetch() }))
// Capture of 'self' with non-sendable type 'Feature' in a `@Sendable` closure
// Consider making struct 'Feature' conform to the 'Sendable' protocol Of cause you could actually attach Do you have any guidance on this topic? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello. 👋 I came over to post a similar message. I, too, have a fairly large number of such warnings. In addition to those you already mentioned, I also have this one Main actor-isolated class 'AppFeatureTests' has different actor isolation from nonisolated superclass 'XCTestCase'; this is an error in Swift 6 which appears in test files when you mark the @MainActor
final class AppFeatureTests: XCTestCase {
func test_something() async { ... }
} A work-around to remove this warning, however, is not to mark the subclass as final class AppFeatureTests: XCTestCase {
@MainActor
func test_something() async { ... }
} |
Beta Was this translation helpful? Give feedback.
-
As @jshier notes, this is a bug in Swift that's fixed on
This can happen for a non-sendable global when you define it as a
I believe this is what Swift wants you to do. Generally it should infer it automatically within the module, though, so it might be worth asking on the Swift forums or opening up an issue on the Swift project. |
Beta Was this translation helpful? Give feedback.
No, most of them are language limitations that are still being filled in by Apple. This includes things like the
KeyPath
warnings which should be fixed in Swift 6 (https://github.com/apple/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md).