[swift-evolution] Allowing `guard let self = self else { ... }` for weakly captured self in a closure.

Chris Lattner clattner at apple.com
Fri Jan 22 19:51:29 CST 2016

> On Jan 5, 2016, at 8:21 PM, Christopher Rogers via swift-evolution <swift-evolution at swift.org> wrote:
> You can shadow self with a guard like you wrote it if use the keyword escaping backquotes like so:
> guard let `self` = self else { return }

To confirm what others have said down thread, this is a compiler bug: this code is valid, but shouldn’t change what references to “self.method()” or “method()" bind to (i.e., explicit or implicit references to self).

Backquotes are for forming a name that happens to overlap with a keyword.  In the case of `self`, this could be because you want to refer to the NSObject.`self` method for some reason.  Backquotes are not a way to name self, init, subscript or any of the other declarations that look like magic identifiers.


More information about the swift-evolution mailing list