[swift-users] Assigning a variable to itself

Saagar Jha saagar at saagarjha.com
Tue Feb 21 19:57:41 CST 2017


It appears that trying to assign a variable to itself is an error:

var foo = 5
foo = foo // error: assigning a variable to itself

However, I was thinking about this and was wondering why this is an error and not a warning. If, for example, the assignment had a side effect (e.g. a didSet block) I’d think it would be warning, possibly ignorable with a set of parentheses. Thoughts?

Saagar Jha

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170221/410a2f43/attachment.html>


More information about the swift-users mailing list