[swift-evolution] [Draft] Throwing Properties and Subscripts

Brent Royal-Gordon brent at architechies.com
Wed Mar 16 08:37:35 CDT 2016


> I wonder if it would help to document the grammar changes necessary in the proposal.

I'm preparing a revision with that information.

> I also wonder how it could affect the getter shorthand? Couldn't the following work for subscripts?
> 
>    subscript(idx: Int) throws -> Element { ... }
> 
>    // the above is shorthand for
>    subscript(idx: Int) -> Element {
>        get throws { ... }
>    }

A shorthand is a definite possibility, especially for subscripts where both accessors might need to throw because of an invalid index, but I decided to keep it simple. I'm also worried that it might encourage people to mark accessors as throwing when only one actually needs it.

> Not sure how this could be extended to work with general computed vars. This doesn't feel right:
> 
>    var x throws: Int { ... }

Yeah, that's another problem.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list