-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
The error message seems to indicate that the compiler thinks that the body
closure is returned and crosses isolation domains but the confusion seems to be caused by sending
the generic return type.
Reproduction
// Compile in Swift 6 mode
func run<Success>(
body: () -> Void
) -> sending Success {
// Returning task-isolated 'body' as a 'sending' result risks causing data races
_run(body: body)
}
func _run<Success>(
body: () -> Void
) -> sending Success {
fatalError()
}
Expected behavior
The snippet should compile without a data race error (although it might warn or error that sending
the return value does not have any effect in this case).
Some workarounds/notes:
- The error only appears in a generic context and not with concrete types (sendable or non-sendable).
- Constraining Success to be Sendable "fixes" the error and the compiler no longer complains about the closure.
- So does making the body closure
sending
or@Sendable
- the compiler does seem to think that the closure is returned across isolation domains and is satisfied if it is sendable
Environment
Xcode 16 beta 6
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels