www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Scoped local variables

reply Jason House <jason.james.house gmail.com> writes:
I'm having my code crash when I add in scope variables.  While it works in some
cases, it doesn't in others.  I've whittled down my current problem to code
that looks like:

unittest{
  scope T t = new T();
}

"T" has a bunch of arrays that it allocates and fills when it's constructed. 
I'm currently confused how this code would cause a crash.  Any insights would
be much appreciated.
Dec 07 2007
parent reply Denton Cockburn <diboss hotmail.com> writes:
On Fri, 07 Dec 2007 09:52:07 -0500, Jason House wrote:

 I'm having my code crash when I add in scope variables.  While it works
 in some cases, it doesn't in others.  I've whittled down my current
 problem to code that looks like:
 
 unittest{
   scope T t = new T();
 }
 
 "T" has a bunch of arrays that it allocates and fills when it's
 constructed.  I'm currently confused how this code would cause a crash. 
 Any insights would be much appreciated.

Need more information. What's the message given when it crashes? Is the cause of the crash the fact that it's scoped? Have you tried without scope? Are you sure it's not in the constructor of T?
Dec 07 2007
next sibling parent reply Jason House <jason.james.house gmail.com> writes:
Denton Cockburn Wrote:

 On Fri, 07 Dec 2007 09:52:07 -0500, Jason House wrote:
 
 I'm having my code crash when I add in scope variables.  While it works
 in some cases, it doesn't in others.  I've whittled down my current
 problem to code that looks like:
 
 unittest{
   scope T t = new T();
 }
 
 "T" has a bunch of arrays that it allocates and fills when it's
 constructed.  I'm currently confused how this code would cause a crash. 
 Any insights would be much appreciated.

Need more information. What's the message given when it crashes?

It's a windows error: housebot-0.7 has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost.
 Is the cause of the crash the fact that it's scoped?  

As best as I can tell.
 Have you tried without scope?

Yes, it works flawlessly without the scope.
 Are you sure it's not in the constructor of T?

I am now. I stripped it down to an empty constructor and removed all member variables. Since posting, I've reduced this down to a simple example. This example sometimes crashes dmd itself instead of producing a crashing executable. I'm using dmd 1.018 with Tango 0.99. Now that I know it's dmd and not me, I may try upgrading the version of dmd that I use. version=crash; //version=work1; //version=work2; //version=work3; interface I{ } class C : public I{ } unittest{ version(crash) scope I def = new C; version(work1) scope C def = new C; version(work2) I def = new C; version(work3) C def = new C; } int main(){ return 0; }
Dec 07 2007
next sibling parent reply Frank Benoit <keinfarbton googlemail.com> writes:
It is a bug. I can reproduce it on linux/dmd.
Would you mind to file a bug report?


Jason House schrieb:
 Denton Cockburn Wrote:
 
 On Fri, 07 Dec 2007 09:52:07 -0500, Jason House wrote:

 I'm having my code crash when I add in scope variables.  While it works
 in some cases, it doesn't in others.  I've whittled down my current
 problem to code that looks like:

 unittest{
   scope T t = new T();
 }

 "T" has a bunch of arrays that it allocates and fills when it's
 constructed.  I'm currently confused how this code would cause a crash. 
 Any insights would be much appreciated.

What's the message given when it crashes?

It's a windows error: housebot-0.7 has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost.
 Is the cause of the crash the fact that it's scoped?  

As best as I can tell.
 Have you tried without scope?

Yes, it works flawlessly without the scope.
 Are you sure it's not in the constructor of T?

I am now. I stripped it down to an empty constructor and removed all member variables. Since posting, I've reduced this down to a simple example. This example sometimes crashes dmd itself instead of producing a crashing executable. I'm using dmd 1.018 with Tango 0.99. Now that I know it's dmd and not me, I may try upgrading the version of dmd that I use. version=crash; //version=work1; //version=work2; //version=work3; interface I{ } class C : public I{ } unittest{ version(crash) scope I def = new C; version(work1) scope C def = new C; version(work2) I def = new C; version(work3) C def = new C; } int main(){ return 0; }

Dec 07 2007
next sibling parent reply Jason House <jason.james.house gmail.com> writes:
Frank Benoit Wrote:

 It is a bug. I can reproduce it on linux/dmd.
 Would you mind to file a bug report?

Before I'd do, I'd like to know if the following things make a difference: 1. Tango vs. Phobos 2. Latest D 1.x vs. latest D 2.x
 
 
 Jason House schrieb:
 Denton Cockburn Wrote:
 
 On Fri, 07 Dec 2007 09:52:07 -0500, Jason House wrote:

 I'm having my code crash when I add in scope variables.  While it works
 in some cases, it doesn't in others.  I've whittled down my current
 problem to code that looks like:

 unittest{
   scope T t = new T();
 }

 "T" has a bunch of arrays that it allocates and fills when it's
 constructed.  I'm currently confused how this code would cause a crash. 
 Any insights would be much appreciated.

What's the message given when it crashes?

It's a windows error: housebot-0.7 has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost.
 Is the cause of the crash the fact that it's scoped?  

As best as I can tell.
 Have you tried without scope?

Yes, it works flawlessly without the scope.
 Are you sure it's not in the constructor of T?

I am now. I stripped it down to an empty constructor and removed all member variables. Since posting, I've reduced this down to a simple example. This example sometimes crashes dmd itself instead of producing a crashing executable. I'm using dmd 1.018 with Tango 0.99. Now that I know it's dmd and not me, I may try upgrading the version of dmd that I use. version=crash; //version=work1; //version=work2; //version=work3; interface I{ } class C : public I{ } unittest{ version(crash) scope I def = new C; version(work1) scope C def = new C; version(work2) I def = new C; version(work3) C def = new C; } int main(){ return 0; }


Dec 07 2007
next sibling parent Frank Benoit <keinfarbton googlemail.com> writes:
Jason House schrieb:
 Frank Benoit Wrote:
 
 It is a bug. I can reproduce it on linux/dmd.
 Would you mind to file a bug report?

Before I'd do, I'd like to know if the following things make a difference: 1. Tango vs. Phobos 2. Latest D 1.x vs. latest D 2.x

I did it on linux, dmd 1.023, tango
Dec 07 2007
prev sibling parent bearophile <bearophileHUGS lycos.com> writes:
Jason House:
 Before I'd do, I'd like to know if the following things make a difference:
 1. Tango vs. Phobos
 2. Latest D 1.x vs. latest D 2.x

On DMD v1.024 with Phobos it seems to work to me. Bye, bearophile
Dec 07 2007
prev sibling parent Jason House <jason.james.house gmail.com> writes:
Frank Benoit wrote:

 It is a bug. I can reproduce it on linux/dmd.
 Would you mind to file a bug report?

This is now issue 1719. Thanks to everyone for testing this under different configurations.
Dec 09 2007
prev sibling parent reply =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jason House wrote:
 version=crash;
 //version=work1;
 //version=work2;
 //version=work3;
 
 interface I{
 }
 
 class C : public I{
 }
 
 unittest{
         version(crash) scope I def = new C;
         version(work1) scope C def = new C;
         version(work2)       I def = new C;
         version(work3)       C def = new C;
 }
 
 int main(){
         return 0;
 }

No problem here with gdc 0.24, phobos and 64-bits linux. Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHWbcWd0kWM4JG3k8RAnemAJ0RRfV1Xl8CfhkMhR//fqv5kC2k3ACgk5vX yHJYQXSvj98yRCxTHlxVENg= =i1X5 -----END PGP SIGNATURE-----
Dec 07 2007
parent Marius Muja <mariusm cs.ubc.ca> writes:
 Jason House wrote:
 version=crash;
 //version=work1;
 //version=work2;
 //version=work3;

 interface I{
 }

 class C : public I{
 }

 unittest{
         version(crash) scope I def = new C;
         version(work1) scope C def = new C;
         version(work2)       I def = new C;
         version(work3)       C def = new C;
 }

 int main(){
         return 0;
 }


Works fine on linux with gdc 0.24 and tango.
Dec 07 2007
prev sibling parent Denton Cockburn <diboss hotmail.com> writes:
On Fri, 07 Dec 2007 17:03:19 -0500, Jason House wrote:

 Frank Benoit Wrote:
 
 It is a bug. I can reproduce it on linux/dmd. Would you mind to file a
 bug report?

Before I'd do, I'd like to know if the following things make a difference: 1. Tango vs. Phobos 2. Latest D 1.x vs. latest D 2.x
 
 Jason House schrieb:
 Denton Cockburn Wrote:
 
 On Fri, 07 Dec 2007 09:52:07 -0500, Jason House wrote:

 I'm having my code crash when I add in scope variables.  While it
 works in some cases, it doesn't in others.  I've whittled down my
 current problem to code that looks like:

 unittest{
   scope T t = new T();
 }

 "T" has a bunch of arrays that it allocates and fills when it's
 constructed.  I'm currently confused how this code would cause a
 crash. Any insights would be much appreciated.

What's the message given when it crashes?

It's a windows error: housebot-0.7 has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost.
 Is the cause of the crash the fact that it's scoped?

As best as I can tell.
 Have you tried without scope?

Yes, it works flawlessly without the scope.
 Are you sure it's not in the constructor of T?

I am now. I stripped it down to an empty constructor and removed all member variables. Since posting, I've reduced this down to a simple example. This example sometimes crashes dmd itself instead of producing a crashing executable. I'm using dmd 1.018 with Tango 0.99. Now that I know it's dmd and not me, I may try upgrading the version of dmd that I use. version=crash; //version=work1; //version=work2; //version=work3; interface I{ } class C : public I{ } unittest{ version(crash) scope I def = new C; version(work1) scope C def = new C; version(work2) I def = new C; version(work3) C def = new C; } int main(){ return 0; }



1.023 on linux using phobos, it works fine. Could it be a tango runtime issue?
Dec 07 2007