www.digitalmars.com         C & C++   DMDScript  

D - BUG: Duplicate variable names allowed inside if() block

reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
This program goes through the compiler ok, although I believe it should
be a syntax error:

    int main() {
      int bar;
      if(true) {
        int bar;
      }
      return 0;
    }

--
The Villagers are Online! http://villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]
Oct 05 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3D9F31D9.F0F445CD deming-os.org...
 This program goes through the compiler ok, although I believe it should
 be a syntax error:

     int main() {
       int bar;
       if(true) {
         int bar;
       }
       return 0;
     }

It is legal, as { } introduces a new scope. -Walter
Oct 07 2002
next sibling parent reply "Dario" <supdar yahoo.com> writes:
 It is legal, as { } introduces a new scope. -Walter

Oh, I thought that duplicate local variables weren't allowed in D. You've written it in the language specs: "It is an error to declare a local variable that hides another local variable in the same function"
Oct 07 2002
parent "Walter" <walter digitalmars.com> writes:
You're right, my goof. I'll log it as a bug. -Walter

"Dario" <supdar yahoo.com> wrote in message
news:ansdvl$m59$1 digitaldaemon.com...
 It is legal, as { } introduces a new scope. -Walter

Oh, I thought that duplicate local variables weren't allowed in D. You've written it in the language specs: "It is an error to declare a local variable that hides another local variable in the same function"

Oct 07 2002
prev sibling next sibling parent "Sean L. Palmer" <seanpalmer directvinternet.com> writes:
I thought you said locals that hide other locals are an error.

Sean

"Walter" <walter digitalmars.com> wrote in message
news:ans8cq$113g$1 digitaldaemon.com...
 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:3D9F31D9.F0F445CD deming-os.org...
 This program goes through the compiler ok, although I believe it should
 be a syntax error:

     int main() {
       int bar;
       if(true) {
         int bar;
       }
       return 0;
     }

It is legal, as { } introduces a new scope. -Walter

Oct 07 2002
prev sibling parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Walter wrote:

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:3D9F31D9.F0F445CD deming-os.org...
 This program goes through the compiler ok, although I believe it should
 be a syntax error:

     int main() {
       int bar;
       if(true) {
         int bar;
       }
       return 0;
     }

It is legal, as { } introduces a new scope. -Walter

I knew that used to be true in C/C++, but I thought that we were getting rid of that. Oh well :) -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Oct 07 2002