i think the 'spirit' of this diagnostic is to deal with the fact that a Mutex
can be populated with a non-Sendable value, but in order to do so it must be known to be in a 'disconnected' isolation region (i.e. is a sending
value). since Mutex grants 'Sendability' to its contents, it must ensure that any subsequent changes to its contents do not alias non-Sendable values from other isolation regions.
as an simplified example, consider:
// non-Sendable type
class NS {}
final class C: Sendable {
let lock = Mutex(NS()) // okay to init since the initial value isn't in any isolation region
func setValue(_ v: NS) {
lock.withLock { existing in
// not okay to assign b/c `v` could have come from another isolation
// region so could introduce a data race
existing = v
} // 🛑
}
}
i feel like what you're 'supposed' to do in this circumstance is ensure the new value being assigned is also known to the compiler to be sending
. AFAIK however, this for some reason still doesn't work currently (see a similar thread here).