[Issue 3878] Arguments and members with the same name

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 3 12:09:09 PDT 2010


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



--- Comment #7 from Stewart Gordon <smjg at iname.com> 2010-10-03 12:08:46 PDT ---
(In reply to comment #6)
> (In reply to comment #5)
> 
>> (In reply to comment #0)
>>> 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.".
>> 
>> It already is required when you want to access the member in such 
>> circumstances.
> 
> I don't know what cases you refer to.

If a function parameter or local variable has the same name as a member of the
class/struct/union in which it is defined, then in order to access the latter
within the former's scope one must use "this.".  Isn't that obvious?

> Probably it's required when there is
> ambiguity for the compiler; but I have said "for the eyes of a programmer".

So you think that "this." should be required for all accesses to members even
when there's no ambiguity?  This could make code rather cluttered.

> Human eyes are not as good as compilers. A good language as D needs to prevent
> human mistakes when possible.

You mean like accidentally naming a local variable the same as a member of the
class, except that at the same time you forget to declare it?

The real solution to the original issue would be to (a) invent an explicit
notation to access a local variable or function parameter (b) make it mandatory
if it's ambiguous with anything else.

But what would the scope of "anything else" be?
* Just members of the class?
* Members of the class and any of its outer classes?
* Anything declared in the same module that is accessible from within the
function?
* Anything declared anywhere in the import tree that is accessible from within
the function?

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


More information about the Digitalmars-d-bugs mailing list