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

Kevin Ballard kevin at sb.org
Wed Jan 6 01:47:29 CST 2016


I actually expected it to create a different identifier that is
unrelated to the keyword, so you can refer to `self` with backticks in
the future to get the version bound by the guard, and self as a keyword
to get the original value of self.

Not that I think this is particularly useful, of course...

-Kevin Ballard

On Tue, Jan 5, 2016, at 08:42 PM, Greg Parker via swift-evolution wrote:
> I think it is a bug  :-)  That's not what backquotes are for. It ought
> to be either supported without the backquotes or banned regardless of
> backquotes.
>
>> On Jan 5, 2016, at 8:34 PM, Jacob Bandes-Storch
>> <jtbandes at gmail.com> wrote:
>>
>> Yes, it seems to use the strong shadowing variable. (The compiler
>> doesn't complain about "self.foo", and "self?.foo" becomes invalid
>> because self is no longer optional.)
>>
>> If it weren't so useful, I'd call it a bug.
>>
>> On Tue, Jan 5, 2016 at 8:34 PM, Greg Parker
>> <gparker at apple.com> wrote:
>>> Does further use of self after that actually use a strong shadowing
>>> variable? Or does it go back to the weak reference it already had as
>>> if the shadow were not there?
>>>
>>>
>>>> On Jan 5, 2016, at 8:26 PM, Jacob Bandes-Storch via swift-evolution
>>>> <swift-evolution at swift.org> wrote:
>>>>
>>>> Wow! I didn't know that worked. It's a bit surprising, and perhaps
>>>> not intended. I think the proposal is still valid.
>>>>
>>>> On Tue, Jan 5, 2016 at 8:21 PM, Christopher Rogers
>>>> <christorogers at gmail.com> 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 }
>>>
>
>
> _________________________________________________
> swift-evolution mailing list swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160105/207cb96f/attachment.html>


More information about the swift-evolution mailing list