更好的错误信息

版本新特性 / Swift 5.2

// *** 以前 ***
// 长表达式中只要错一处,编译器就会放弃整行,并报出:
// "expression was too complex to be solved in reasonable time"
// 或 "type of expression is ambiguous without more context",
// 而插入符还指在最开头
let totalOld = ["1", "2"].map { Int($0) }.reduce(0, +)

// *** 在 5.2 版本中 ***
// 类型检查器经过重写,出错后仍会继续,因此能指出确切的位置和确切的问题:
// "value of optional type 'Int?' must be unwrapped to a value of type 'Int'"
let total = ["1", "2"].compactMap { Int($0) }.reduce(0, +)
print(total)

// 类型缺少成员时,现在会建议最接近的名称,
// 参数标签写错时给出修正建议,而不是一堆重载