[swift-evolution] Proposal: Re-instate mandatory self for accessing instance properties and functions (David Hart)

Jeremy Pereira jeremy.j.pereira at googlemail.com
Thu Dec 17 08:20:30 CST 2015


> On 17 Dec 2015, at 14:22, Stephen Celis <stephen.celis at gmail.com> wrote:
> 
>> On Dec 17, 2015, at 4:54 AM, Jeremy Pereira via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> There are other ways to achieve the goal, for example Java has a warning that explicitly tells you when your local variable is shadowing an instance variable. Why wouldn’t that work?
> 
> The main arguments I've seen are around initializers and let-unwrapping:
> 
>     init(foo: Int) {
>         self.foo = foo
>     }
> 
>     guard let foo = foo else { return }
> 
> I'm curious if there are more. I think both of these could be special-cased.
> 
> Stephen


In Java, I have the warning enabled for local variables but not function arguments precisely so that I can use the  this.x = x pattern in constructors. The pattern is so common in Swift that I would that the init is explicitly excluded and so are the optional binding statements and guard.


More information about the swift-evolution mailing list