-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
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 following snippet compiles successfully using Swift 6.2 but fails to compile with the most recent main snapshot.
A reference to a MainActor isolated instance is first weakly captured in a non-isolated closure. Then that weak reference is captured in a MainActor isolated closure but the compiler erroneously won't allow accessing it there.
No error when capturing a strong reference or turning the weak ref into a strong one before capturing it in the inner, isolated, closure.
Reproduction
// Compile with: swiftc -swift-version 6
func notIsolated(_: @Sendable () -> Void) {}
func onMainActor(_: @MainActor () -> Void) {}
@MainActor
final class IsolatedClass {
func foo() {
notIsolated { [weak self] in
onMainActor {
// error: sending 'self' risks causing data races [#SendingRisksDataRace]
_ = self
}
}
}
}Expected behavior
Compiles successfully
Environment
main-snapshot-2025-11-03 installed via swiftly
Apple Swift version 6.3-dev (LLVM bff1370bd79c983, Swift 57cf4ce)
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