[swift-evolution] Subscripts assignable to closure vars

Jordan Rose jordan_rose at apple.com
Fri Sep 15 16:55:24 CDT 2017



> On Sep 15, 2017, at 13:00, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> On Sep 15, 2017, at 3:45 PM, Joanna Carter via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Just came across this.
>> 
>> I want to be able to hold onto the reference to a subscript "method" for later use.
>> 
>> Assigning the subscript to a var in the init of a type raises a segmentation fault.
>> 
>> Should this - could this - be allowed?
> 
> It really shouldn't be allowed.  I think KeyPaths are the intended language solution here.
> 
> Please file a bug about the crash, though.

The crash is already fixed in master, thanks to Alex Hoppen's work on making actual subscripts distinct from the name "subscript".

I think John's right that this should not be allowed. After all, a subscript may have both a getter and a setter, and it's not immediately obvious from your syntax which one you mean.

We could invent some kind of answer for this (including simply just checking the contextual type), but it would be niceā„¢ if any such solution also had a good answer for properties. Or we could just make key paths and closures work a little better together, which has also been discussed on the list.

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


More information about the swift-evolution mailing list