You might expect this code to work:
func aFunction() -> Int? { return 5 }
func bFunction() throws -> Int { return 4 }
let value = aFunction() ?? try bFunction() // ERROR: Operator can throw but
expression is not marked with a ‘try'
print(value)
Instead, you must put the ‘try’ before the entire expression:
let value = try aFunction() ?? bFunction()
This is awkward, since aFunction() doesn’t throw.
I propose we change the grammar to allow the first example and disallow the
second, consistent with the idea that throwing calls are ‘marked’ by using the
try keyword.
Karl
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution