www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - dmd .126 scope bug?

reply clayasaurus <clayasaurus gmail.com> writes:
The following code compiles fine and crashes. I think it should produce 
an error that foo is already defined? It took a while for me to catch it.

class Foo
{
    void dostuff() {}
}

Foo foo;

void init()
{
    Foo foo = new Foo;
}

int main()
{
    init();

    foo.dostuff();
}
Jun 10 2005
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"clayasaurus" <clayasaurus gmail.com> wrote in message
news:d8dsit$2nft$1 digitaldaemon.com...
 The following code compiles fine and crashes. I think it should produce
 an error that foo is already defined?

Being able to redeclare names inside scopes is the whole point of having scopes.
Jun 10 2005
next sibling parent Hasan Aljudy <hasan.aljudy gmail.com> writes:
Walter wrote:
 "clayasaurus" <clayasaurus gmail.com> wrote in message
 news:d8dsit$2nft$1 digitaldaemon.com...
 
The following code compiles fine and crashes. I think it should produce
an error that foo is already defined?

Being able to redeclare names inside scopes is the whole point of having scopes.

Yeah, the problem here isn't exactly scope, it's the use of an un-initialized variable. Shouldn't that produce some sort of error? (I read that the compiler doesn't produce warnings; it's either an error or not).
Jun 10 2005
prev sibling parent reply clayasaurus <clayasaurus gmail.com> writes:
Walter wrote:
 "clayasaurus" <clayasaurus gmail.com> wrote in message
 news:d8dsit$2nft$1 digitaldaemon.com...
 
The following code compiles fine and crashes. I think it should produce
an error that foo is already defined?

Being able to redeclare names inside scopes is the whole point of having scopes.

I guess my main problem is that, I wasn't able to use an assert to catch it! class Foo { void dostuff() {} } Foo foo; void init() { Foo foo = new Foo; } int main() { init(); assert(foo is null); foo.dostuff(); } Shouldn't this through an assert error? *confused*
Jun 11 2005
parent clayasaurus <clayasaurus gmail.com> writes:
nevermind.

clayasaurus wrote:
 Walter wrote:
 
 "clayasaurus" <clayasaurus gmail.com> wrote in message
 news:d8dsit$2nft$1 digitaldaemon.com...

 The following code compiles fine and crashes. I think it should produce
 an error that foo is already defined?

Being able to redeclare names inside scopes is the whole point of having scopes.

I guess my main problem is that, I wasn't able to use an assert to catch it! class Foo { void dostuff() {} } Foo foo; void init() { Foo foo = new Foo; } int main() { init(); assert(foo is null); foo.dostuff(); } Shouldn't this through an assert error? *confused*

Jun 11 2005
prev sibling parent reply James McComb <alan jamesmccomb.id.au> writes:
clayasaurus wrote:

 The following code compiles fine and crashes. I think it should produce 
 an error that foo is already defined? It took a while for me to catch it.

It does produce an error, but only if you use the -w compiler switch. You'll get the following warning: function main no return at end of function James McComb
Jun 11 2005
parent reply clayasaurus <clayasaurus gmail.com> writes:
James McComb wrote:
 clayasaurus wrote:
 
 The following code compiles fine and crashes. I think it should 
 produce an error that foo is already defined? It took a while for me 
 to catch it.

It does produce an error, but only if you use the -w compiler switch. You'll get the following warning: function main no return at end of function James McComb

Erm... that just means it wants a return 0 at the end of main, which wasn't my problem.
Jun 11 2005
parent reply James McComb <alan jamesmccomb.id.au> writes:
clayasaurus wrote:

 Erm... that just means it wants a return 0 at the end of main, which 
 wasn't my problem.

Right you are. I must have had a brain malfunction. ;) James McComb
Jun 11 2005
parent clayasaurus <clayasaurus gmail.com> writes:
James McComb wrote:
 clayasaurus wrote:
 
 Erm... that just means it wants a return 0 at the end of main, which 
 wasn't my problem.

Right you are. I must have had a brain malfunction. ;) James McComb

I've had plenty of those too lately :-/
Jun 11 2005