dlang-community / D-Scanner

Swiss-army knife for D source code
Boost Software License 1.0
242 stars 80 forks source link

Warn when not accessing member variable through `this` #942

Open cwinter158 opened 12 months ago

cwinter158 commented 12 months ago

What are thoughts on issuing a warning when accessing a member variable without going through the this reference?

struct A {
    int i;

    this(int i)
    {
        i = i; // <-- Warning
        this.i = i; // <-- Ok
    }
}

My request is motivated by the specific issue highlighted in this example, but this check in general would remove some ambiguities, especially in constructors (I don't know easy it would be to limit the check to constructors, though).

It would surely be extremely noisy for most projects, so maybe would make most sense to be disabled by default.