[swift-evolution] [Pitch] Change location of 'try' for infix operators

Karl razielim at gmail.com
Tue Oct 11 02:04:07 CDT 2016

> On 11 Oct 2016, at 08:49, Benjamin Spratling <bspratling at mac.com> wrote:
> Howdy,
> The error message is not saying that aFunction throws, it says “??" might throw.  After all, you supplied a ()rethrows->(Int) to it as its second argument, which is wrapping a ()throws->Int, “bFunction()"
> ?? and && and || wrap the trailing expression in an @autoclosure.
> I am a little surprised two “try” are not required.  This would be my expectation:
>> let value = try aFunction() ?? try bFunction()
> but, using try to the right of a non-assignment operator is not allowed.
> This, however, is not disallowed:
> let value = try aFunction() ?? (try bFunction())
> The purpose of the @autoclosure is to make developers forget they need to write a closure, and it apparently worked for you.
> -Ben Spratling

Yeah, I understand the reason for it, but I still think we should change it so you write the ‘try’ before the part which actually throws. Perhaps the rule should be something more general around rethrowing autoclosures?

After all, I thought that was the entire point of the ‘try’ keyword. The compiler doesn't really need it (it already knows what throws and what doesn’t), but it helps humans to mark where the throwing stuff happens.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161011/a0ec4961/attachment.html>

More information about the swift-evolution mailing list