Summary: Arguments and attributes with the same name
           Product: D
           Version: 2.041
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-03-04 07:50:13 PST ---
This D2 program compiles:

class Foo {
    int x;
    this(int x) { x = x; }
    void inc(int x) { this.x += x; }
class Bar {
    int x;
    this() { x = 5; }
struct Spam {
    static int x;
    void inc(int x) { Spam.x += x; }
void main() {}

The compiler has no problems in knowing what variables are each of those (and
maybe a good IDE too can tell them apart well, and give different colors to
arguments and attributes), but for the eye of a programmer that's not using
such IDE that code is confusing enough (because the "this." is optional in D).

I see two possible solutions to avoid that mess:

The solution I prefer: the compiler can give an error when an argument has the
same name of an attribute. This is more tidy.

Less restricting solution: in only those cases, where there can be ambiguity
for the eyes of a programmer, the compiler can require the use of "this.".


Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to