Avatar
swiftbot BOT 10/1/2018 3:56 PM
Author icon
omochimetaru
class Cat { init() { print("init cat") } deinit { print("deinit cat") } func nya() -> () -> Void { print("begin nya") weak var wself = self var stone = Int(2) { didSet { guard let self = wself else { return } print(self) } } print("end nya") return { print(stone) } } } func main() { var cap: (() -> Void)? = nil do { print("---1---") let cat = Cat() print("---2---") cap = cat.nya() } // end of `cat` print("---3---") cap = nil print("---4---") } main()
Version:
swift-4.1.1-RELEASE
Output:
Error:
/usercode/main.swift:26:9: warning: variable 'cap' was written to, but never read var cap: (() -> Void)? = nil ^ /usercode/main.swift:12:23: error: pattern matching in a condition requires the 'case' keyword guard let self = wself else { ^ case /usercode/main.swift:12:27: error: expression pattern of type 'Cat' cannot match values of type 'Cat?' guard let self = wself else { ^~~~ ?