> On 1 Nov 2016, at 01:37, Joe Groff via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> Sorry for piling onto the bikeshed. We do already have a notation for testing 
> that an Optional isn't nil, `x != nil`. We could theoretically bless `<decl 
> ref> != nil` as a statement condition to also unwrap the referenced 
> declaration in the scope guarded by the condition. (`<decl ref> is T` could 
> similarly rebind a declaration as the cast type.)
> 
> -Joe

Was about the say the same thing; this is basically the same idea as type 
narrowing, which is something I think that Swift still really needs, and can be 
used to solve this problem without the need for new syntax, enabling things 
like:

        if (a is Foo) { a.someMethodSpecificToFoo() }
        if (a != nil) { a.someMethodWithoutUnwrapping() }

While I've often suggested keywords to solve other problems, I'm not sure if we 
really need one to solve this use-case!
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to