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

[Swift 6] No diagnostic when explicitly capturing a non-sendable value #79815

Open
rraphaeldev opened this issue Mar 6, 2025 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@rraphaeldev
Copy link

Description

When explicitly capturing a non-sendable value in a Task closure, no diagnostic is raised.

Reproduction

class NonSendable {
    func action() async {}
}

@MainActor
final class Foo {
    let value = NonSendable()

    func perform() {
        Task { [value] in
            await value.action() // no error, but can cause data races
        }

        Task {
            await value.action() // error: sending 'self.value' risks causing data races
        }
    }
}

Expected behavior

A data race diagnostic should most likely be raised even when value is manually captured in the task closure.

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

Additional information

Swift forums question: https://forums.swift.org/t/task-capture-list-silence-data-race-error/78275

@rraphaeldev rraphaeldev added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 6, 2025
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

1 participant