Use `withThrowingTaskGroup` within Actor leads to `Non-sendable type '(inout ThrowingTaskGroup<Void, any Error>) async throws -> ()'` compilation warning

When using compilation flag -warn-concurrency and -enable-actor-data-race-checks (possibly without? Not tried...)

actor ConnectorActor {
    struct Config {}
    private let config: Config
    init(config: Config) {
        self.config = config
    }
    func connect() async {
        await withThrowingTaskGroup(of: Void.self) { group in
            group.addTask {
                /* ... */
            }
         
        }
    }
}
Non-sendable type '(inout ThrowingTaskGroup<Void, any Error>) async throws -> ()' exiting actor-isolated context in call to non-isolated global function 'withThrowingTaskGroup(of:returning:body:)' cannot cross actor boundary

But if I wrap the withThrowingTaskGroup within a Task the warning goes away, like so:

    func connect() async {
        Task {
            await withThrowingTaskGroup(of: Void.self) { group in
                group.addTask {
                    /* ... */
                }
                
            }
        }
    }

What is the best practices here?

1 Like

This was recently fixed in top-of-tree:

You should be able to ignore the warning for now.

2 Likes

With Xcode 14.1 Beta 2 (swiftlang-5.7.1.131.4 clang-1400.0.29.51), I see the same warning for reduce(into:) when I use it in MainActor as below.
Is this related and I should ignore it for now or this is legit?

I have seen this warning to, and it felt a bit too overly strict