示例工程 05-control-flow-pattern-matching

05-control-flow-pattern-matching/Diagnostics/GuardFallsThrough.swift

swift · 0.2 KB

// 故意编译失败:guard 的 else 分支不能落空。
// 复现:swiftc Diagnostics/GuardFallsThrough.swift
func check(_ value: Int) {
    guard value > 0 else {
        print("negative")
    }
    print(value)
}
 
check(1)