[swift-evolution] Move placement of 'throws' statement
Dave Abrahams
dabrahams at apple.com
Wed Dec 28 11:52:15 CST 2016
on Tue Dec 27 2016, Chris Lattner <clattner-AT-apple.com> wrote:
> On Dec 26, 2016, at 2:55 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>>>
>>> // Move `throws` to the end
>>> func baz() -> String throws
>>
>> I agree that reads much better.
>
> This doesn’t work unless you’re willing to break consistency with
> function type syntax, or if you’re willing to make function
> [type/decl] syntax ambiguous.
>
> How would you express this, for example?
>
> let x : (_ a : Int) throws -> (_ b: Float) throws -> Double
>
> it would be ambiguous to move the ‘throws’ keyword to the end of the
> function type, because you'd get:
>
> let x : (_ a : Int) -> (_ b: Float) -> Double throws throws
I see.
We *could* say that the "throws" keyword comes after the return type
unless it's a function type, in which case it comes after the return
type's parameter list
let x : (_ a : Int) -> (_ b: Float) throws -> Double throws
I admit this is a horrible rule from a language designer's point of view
but there's a chance it could end up being better for users.
Functions-that-return-functions are, after all, the 0.1% case.
--
-Dave
More information about the swift-evolution
mailing list