Last active
March 22, 2022 04:02
-
-
Save inamiy/6ee65da1424b3f8837f51e9fe13b1a25 to your computer and use it in GitHub Desktop.
Swift @mainactor + @sendable closure transitive rule https://twitter.com/inamiy/status/1506118628839546880
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import _Concurrency | |
// https://twitter.com/inamiy/status/1506118628839546880 | |
var f: () -> () = {} | |
var fSendable: @Sendable () -> () = {} | |
var fMain: @MainActor () -> () = {} | |
var fMainSendable: @MainActor @Sendable () -> () = {} | |
// @Sendable clsoure -> normal closure | |
f = fSendable | |
//fSendable = f // ERROR | |
// @Sendable closure -> @MainActor closure | |
fMain = fSendable | |
//fSendable = fMain // ERROR | |
// normal closure -> @MainActor closure | |
fMain = f | |
//f = fMain // ERROR | |
// @Sendable closure -> @MainActor @Sendable closure | |
fMainSendable = fSendable | |
//fSendable = fMainSendable // ERROR | |
//f = fMainSendable // ERROR | |
//fMainSendable = f // ERROR | |
// @MainActor @Sendable closure -> @MainActor closure | |
fMain = fMainSendable | |
//fMainSendable = fMain // ERROR | |
// Conclusion: | |
// | |
// 1. @Sendable -> normal -> @MainActor | |
// 2. @Sendable -> @MainActor @Sendable -> @MainActor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment