www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Entity name shadowing: valid or not ?

reply Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Is entity (aka symbol?) name shadowing valid or not in D?
In statement.html the spec says:
"A block statement introduces a new scope for local symbols. A local 
symbol's name, however, must be unique within the function.

...

   void func2(){

     int x;
     {
       int x;	// illegal, x is multiply defined in function scope
     }
   }
"

However that same code segment compiles quite ok. Also, in mixin.html, 
the first example uses name shadowing to illustrate the use of mixins.


-- 
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to 
be... unnatural."
Oct 24 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Bruno Medeiros wrote:
 Is entity (aka symbol?) name shadowing valid or not in D?
 In statement.html the spec says:
 "A block statement introduces a new scope for local symbols. A local 
 symbol's name, however, must be unique within the function.
 
 ...
 
   void func2(){
 
     int x;
     {
       int x;    // illegal, x is multiply defined in function scope
     }
   }
 "
 
 However that same code segment compiles quite ok.
-> digitalmars.D.bugs
 Also, in mixin.html, 
 the first example uses name shadowing to illustrate the use of mixins.
Yes, if mixins are an exception to this rule, then it should be documented. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Oct 26 2005
parent Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
Stewart Gordon wrote:
 Bruno Medeiros wrote:
 
 Is entity (aka symbol?) name shadowing valid or not in D?
 In statement.html the spec says:
 "A block statement introduces a new scope for local symbols. A local 
 symbol's name, however, must be unique within the function.

 ...

   void func2(){

     int x;
     {
       int x;    // illegal, x is multiply defined in function scope
     }
   }
 "

 However that same code segment compiles quite ok.
-> digitalmars.D.bugs
 Also, in mixin.html, the first example uses name shadowing to 
 illustrate the use of mixins.
Yes, if mixins are an exception to this rule, then it should be documented. Stewart.
Well, but is it a rule or is it not? I'd still like to hear from Walter about it. -- Bruno Medeiros - CS/E student "Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
Oct 29 2005