Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong error when passing sending closure to TaskGroup #76242

Open
netural-philipp-gabriel opened this issue Sep 4, 2024 · 2 comments
Open

Wrong error when passing sending closure to TaskGroup #76242

netural-philipp-gabriel opened this issue Sep 4, 2024 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@netural-philipp-gabriel
Copy link

netural-philipp-gabriel commented Sep 4, 2024

Description

The compiler produces an error when passing a sending closure to a TaskGroup. However if you pass the same closure to a Task this error does not pop up, which makes me think that TaskGroups behavior is not correct.

Reproduction

func send(
    operation: sending @escaping () async -> Void
) async {
    await withTaskGroup(of: Void.self) { taskGroup in
        taskGroup.addTask { // error: Passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure
            await operation()
        }
    }
}

Expected behavior

No compiler error.

Environment

Apple Swift version 6.0-dev (LLVM c3efe9282719c35, Swift b163fed)
Target: arm64-apple-macosx14.0

Additional information

No response

@netural-philipp-gabriel netural-philipp-gabriel added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 4, 2024
@jamieQ
Copy link
Contributor

jamieQ commented Sep 4, 2024

relevant forum post: https://forums.swift.org/t/new-task-creation-apis/74322

@netural-philipp-gabriel
Copy link
Author

Hmm, not even capturing the closure as nonisolated(unsafe) seems to be working. I am getting the feeling I am holding it wrong. I pretty much just copied the parameter as it is used in TaskGroup.addTask 😕.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants