[swift-evolution] guard let x = x
Thorsten Seitz
tseitz42 at icloud.com
Fri Nov 4 00:55:43 CDT 2016
vars cannot be type narrowed as soon as concurrency comes into play. That's why Ceylon restricts type narrowing to immutables.
-Thorsten
> Am 03.11.2016 um 09:52 schrieb Martin Waitz via swift-evolution <swift-evolution at swift.org>:
>
> Am 2016-11-03 09:17, schrieb Pyry Jahkola via swift-evolution:
>> As pleasing as it sounds*), the idea of type narrowing breaks down
>> badly if:
>> – the binding is implicit (without explicit extra syntax involved)
>> and
>> – what is bound happens to be mutable.
>> An example being:
>> // VAR message: String?
>> IF message != NIL { // magic turns 'message' into a non-optional
>> 'String' here
>> handleMessage(message)
>> message = NIL // 'String' is not 'ExpressibleByNilLiteral'
>> }
>> What magic would we require to still allow access to the Optional
>> interface of 'message' in that block? In other words, I'm afraid type
>> narrowing for Swift's enums (including Optional) isn't quite as simple
>> as that.
>
> No magic would be required.
> Just don't turn into non-optional but into implicitly unwrapped optional.
>
> And only do so while the compiler can prove that it is non-nil.
> I.e. after your `message = nil` line, it would be handled just like any other optional again.
>
> --
> Martin
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list