Skip to content

Instantly share code, notes, and snippets.

@mattmassicotte
Created September 22, 2023 10:30
Show Gist options
  • Save mattmassicotte/d0b2b4eddf7c0c2ca7bdf3d516bb5f86 to your computer and use it in GitHub Desktop.
Save mattmassicotte/d0b2b4eddf7c0c2ca7bdf3d516bb5f86 to your computer and use it in GitHub Desktop.
Capturing a non-Sendable in a @sendable closure that produces no warning
struct NonSendable {
}
@available(*, unavailable)
extension NonSendable: Sendable {
}
actor MyActor {
let nonSendable: NonSendable
init(nonSendable: @Sendable () -> NonSendable) {
self.nonSendable = nonSendable()
}
}
let nonSendable = NonSendable()
// why don't I get a warning about capturing a non-sendable value here?
let actor = MyActor(nonSendable: { nonSendable })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment