Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
June 11, 2005 dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | "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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | 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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to James McComb | 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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | 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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | 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 Re: dmd .126 scope bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to James McComb | 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 :-/
|
Copyright © 1999-2021 by the D Language Foundation