www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - needThis() bug

reply Tiago Gasiba <tiago.gasiba gmail.com> writes:
Hi,

The following code is wrong and makes the compiler crash:

------ CODE ------
class FOO{
  struct S {
    int a;
  }

  S st;

  static int f( int a ){
    return st.a;
  }
}
------ CODE ------

Execution:
dmd bug.d
dmd: tocsym.c:142: virtual Symbol* VarDeclaration::toSymbol(): Assertion
`!needThis()' failed.
Abgebrochen

Tiago

-- 
Tiago Gasiba (MSc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
Oct 24 2005
next sibling parent reply "Lionello Lunesu" <lio remove.lunesu.com> writes:
Hi..

It's seems a compile error: "st" is a member of the class FOO. You can't 
reference a member inside a static method, since the static methods has no 
"this" to work on. You need an instance of FOO to be able to access "st".

Unfriendly error message though.

L.

"Tiago Gasiba" <tiago.gasiba gmail.com> wrote in message 
news:dji2d3$acl$1 digitaldaemon.com...
 Hi,

 The following code is wrong and makes the compiler crash:

 ------ CODE ------
 class FOO{
  struct S {
    int a;
  }

  S st;

  static int f( int a ){
    return st.a;
  }
 }
 ------ CODE ------

 Execution:
 dmd bug.d
 dmd: tocsym.c:142: virtual Symbol* VarDeclaration::toSymbol(): Assertion 
 `!needThis()' failed.
 Abgebrochen

 Tiago

 -- 
 Tiago Gasiba (MSc.) - http://www.gasiba.de
 Everything should be made as simple as possible, but not simpler. 

Oct 24 2005
parent Carlos Santander <csantander619 gmail.com> writes:
Lionello Lunesu escribió:
 Hi..
 
 It's seems a compile error: "st" is a member of the class FOO. You can't 
 reference a member inside a static method, since the static methods has no 
 "this" to work on. You need an instance of FOO to be able to access "st".
 

That's why he said "the following code is wrong"
 Unfriendly error message though.
 

That's the bug: it shouldn't crash the compiler.
 L.
 
 "Tiago Gasiba" <tiago.gasiba gmail.com> wrote in message 
 news:dji2d3$acl$1 digitaldaemon.com...
 
Hi,

The following code is wrong and makes the compiler crash:

------ CODE ------
class FOO{
 struct S {
   int a;
 }

 S st;

 static int f( int a ){
   return st.a;
 }
}
------ CODE ------

Execution:
dmd bug.d
dmd: tocsym.c:142: virtual Symbol* VarDeclaration::toSymbol(): Assertion 
`!needThis()' failed.
Abgebrochen

Tiago

-- 
Tiago Gasiba (MSc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler. 


-- Carlos Santander Bernal
Oct 25 2005
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tiago Gasiba schrieb am 2005-10-24:
 Hi,

 The following code is wrong and makes the compiler crash:

 ------ CODE ------
 class FOO{
   struct S {
     int a;
   }

   S st;

   static int f( int a ){
     return st.a;
   }
 }
 ------ CODE ------

 Execution:
 dmd bug.d
 dmd: tocsym.c:142: virtual Symbol* VarDeclaration::toSymbol(): Assertion
`!needThis()' failed.
 Abgebrochen

 Tiago

Added to DStress as http://dstress.kuehne.cn/nocompile/b/bug_tocsym_142_A.d http://dstress.kuehne.cn/nocompile/b/bug_tocsym_142_B.d http://dstress.kuehne.cn/nocompile/b/bug_tocsym_142_C.d http://dstress.kuehne.cn/nocompile/b/bug_tocsym_142_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDYaI63w+/yD4P9tIRAl+GAJ96Iyhj5GgaGZsykVuYCEKGP7JliACgv7Dn OYZkHJHgL0aPEVRZvfLkRlE= =A1zX -----END PGP SIGNATURE-----
Oct 28 2005