http://d.puremagic.com/issues/show_bug.cgi?id=3878

           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
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 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.".


Discussion:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=106970

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to