我在Swift中测试function is first class citizen
。我遇到了麻烦检查以下代码:
let f: Int -> Int = { $0 }
if f is (Int -> Int?) { // compiler warning: 'is' test is always true
print("hello")
} else {
print("ops") // runtime: this line is executed
}
我在if
行中收到编译器警告说:"'''测试永远是真的"。但是当我运行代码时,控制台打印"操作"这意味着is
测试是错误的。这让我很困惑。为什么编译器在运行时声明为false时表示为真?