Thread overview
needThis() bug
Oct 24, 2005
Tiago Gasiba
Oct 25, 2005
Lionello Lunesu
Oct 26, 2005
Carlos Santander
Oct 28, 2005
Thomas Kuehne
October 24, 2005
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.
October 25, 2005
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.


October 26, 2005
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
October 28, 2005
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