Thread overview
dmd .126 scope bug?
Jun 11, 2005
clayasaurus
Jun 11, 2005
Walter
Jun 11, 2005
Hasan Aljudy
Jun 11, 2005
clayasaurus
Jun 11, 2005
clayasaurus
Jun 11, 2005
James McComb
Jun 11, 2005
clayasaurus
Jun 12, 2005
James McComb
Jun 12, 2005
clayasaurus
June 11, 2005
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();
}
June 11, 2005
"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.


June 11, 2005
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).
June 11, 2005
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
June 11, 2005
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.
June 11, 2005
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*
June 11, 2005
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*
June 12, 2005
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
June 12, 2005
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 :-/