Thread overview
BUG: Duplicate variable names allowed inside if() block
Oct 05, 2002
Russ Lewis
Re: Duplicate variable names allowed inside if() block
Oct 07, 2002
Walter
Oct 07, 2002
Dario
Oct 07, 2002
Walter
Oct 07, 2002
Sean L. Palmer
Oct 07, 2002
Russ Lewis
October 05, 2002
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))) ]


October 07, 2002
"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


October 07, 2002
> 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"


October 07, 2002
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


October 07, 2002
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))) ]


October 07, 2002
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"
>
>