[swift-evolution] [Idea] Allowing most keywords after "."

Chris Lattner clattner at apple.com
Sat Feb 27 23:58:55 CST 2016


> On Feb 27, 2016, at 6:05 AM, Stephen Celis via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On Feb 27, 2016, at 8:37 AM, Radosław Pietruszewski via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> +1, that makes a lot of sense.
>> 
>> Q: Is `case default` in enum context ambiguous? In case I’m forgetting something, `default` is only used in `switch` contexts. So… couldn’t we make the keyword context dependent?
> 
> According to the grammar, `default` is indeed only used in `switch`: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/default-label
> 
> I have two thoughts:
> 
> 1. Is it possible to reconsider reusing another keyword, `else`, as Ruby does?
> 
> 2. Could the parser scan the leading `.` to prevent the need for escaping cases named "default", or would this unnecessarily complicate the compiler?

“default” isn’t core to Doug’s proposal.  There are other keywords that are problematic as well, particularly as we start importing more and more global constants as members (because of https://github.com/apple/swift-evolution/blob/master/proposals/0033-import-objc-constants.md).

Besides that, we’ve talked about default before: https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md  We could definitely make it context sensitive within refutable patterns (or something) but this doesn’t define away the need for something like Doug’s proposal.

-Chris


More information about the swift-evolution mailing list