Thread overview
static block attribute to 'this'
Oct 30, 2004
tetsuya
Oct 31, 2004
Thomas Kuehne
Nov 01, 2004
tetsuya
Nov 08, 2004
Walter
October 30, 2004
dmd 0.105, winXP

the static attribute followed by a block statement seems
not to affect this() in the scope.

the following code1 & code2 work fine, but not code3.

<code1>
class X
{
static { int x; }
static this() { x = 2; }
unittest { assert(x == 2); }
}
</code1>

<code2>
class X
{
static { int x; static this() { x = 2; } }
unittest { assert(x == 2); }
}
</code2>

<code3>
class X
{
static { int x; this() { x = 2; } }
unittest { assert(x == 2); }       // fails
}
</code3>


btw, how the heck can i indent my code in the post ???
all the spaces & tabs at the top of a line disappears
when i post it... ugly code..  :(((

tetsuya


October 31, 2004
tetsuya schrieb:
> dmd 0.105, winXP
>
> the static attribute followed by a block statement seems
> not to affect this() in the scope.

added to dstress as svn://svn.kuehne.cn/dstress/run/static_14.d svn://svn.kuehne.cn/dstress/run/static_15.d svn://svn.kuehne.cn/dstress/run/static_16.d

> btw, how the heck can i indent my code in the post ???
> all the spaces & tabs at the top of a line disappears
> when i post it... ugly code..  :(((
1) write your post in a text editor.
2) when you're done select a single tab from you text, copy it.
3) then call the replace function paste in the tab and replace it with any number of spaces
you like.

Thomas


November 01, 2004
In article <cm3ogi$1ulg$1@digitaldaemon.com>, Thomas Kuehne says...
>
>tetsuya schrieb:
>> dmd 0.105, winXP
>>
>> the static attribute followed by a block statement seems
>> not to affect this() in the scope.
>
>added to dstress as svn://svn.kuehne.cn/dstress/run/static_14.d svn://svn.kuehne.cn/dstress/run/static_15.d svn://svn.kuehne.cn/dstress/run/static_16.d
>
>> btw, how the heck can i indent my code in the post ???
>> all the spaces & tabs at the top of a line disappears
>> when i post it... ugly code..  :(((
>1) write your post in a text editor.
>2) when you're done select a single tab from you text, copy it.
>3) then call the replace function paste in the tab and replace it with any number of spaces
>you like.
>
>Thomas
>
>

sorry, i don't get your suggestion well.
you mean this way?
1) write your post in a text editor.
2) when you're done, use tabs to indent your code.
3) then replace tabs with appropriate number of white spaces.
if so, then it isn't still working for me.

i'm posting from Mozilla Navigator
and maybe that is a problem somehow

thanks anyway

tetsuya


November 08, 2004
"tetsuya" <tetsuya_member@pathlink.com> wrote in message news:cm057b$13nu$1@digitaldaemon.com...
> dmd 0.105, winXP
>
> the static attribute followed by a block statement seems
> not to affect this() in the scope.
>
> the following code1 & code2 work fine, but not code3.
>
> <code1>
> class X
> {
> static { int x; }
> static this() { x = 2; }
> unittest { assert(x == 2); }
> }
> </code1>
>
> <code2>
> class X
> {
> static { int x; static this() { x = 2; } }
> unittest { assert(x == 2); }
> }
> </code2>
>
> <code3>
> class X
> {
> static { int x; this() { x = 2; } }
> unittest { assert(x == 2); }       // fails
> }
> </code3>

This is by design. 'static this' is considered as special, and not as a static attribute followed by a declaration.