With all the special handling of self in captures, I wonder whether it should also be given additional restrictions. This code, for example, would be legal but confusing:
class C {
static var global: C? = C(name: "global C")
let name: String
func identify() { print("hello I am \(name)!") }
func identifyLater() {
Task { [weak self] in
guard let self = self ?? C.global else { return }
identify() // What does this print?
}
}
Perhaps it should be illegal to re-bind self to anything but the result of successfully unwrapping weak self in a closure that captures self.