Skip to content

Wrong error when passing sending closure to TaskGroup #76242

@netural-philipp-gabriel

Description

@netural-philipp-gabriel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions