[swift-evolution] guard let x = x

Tino Heth 2th at gmx.de
Thu Nov 3 03:44:15 CDT 2016


> if x != nil {
> 		// x is definitely not nil inside this block (implicitly unwrapped)

Pyry already mentioned the problem that arise when x is a variable (is "x = nil" forbidden inside the block?).
Properties add complications as well (especially, but not only, computed ones), and everything beyond simple checks for nil would be a potential source of big confusion:
if (x == y) {
What if one of the values can change? Forbidding that would be odd, but if you don't oppose strict limits, there is no way to guarantee that the initial conditions are still valid throughout the block.

In general, I think Swifts approach is very good, because it saves us from the "magic" that has to be involved when the compiler infers traits based on checks done in the source.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161103/3293159e/attachment.html>


More information about the swift-evolution mailing list