www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - static block attribute to 'this'

reply tetsuya <tetsuya_member pathlink.com> writes:
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
Oct 30 2004
next sibling parent reply "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
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..  :(((

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
Oct 31 2004
parent tetsuya <tetsuya_member pathlink.com> writes:
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..  :(((

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
Nov 01 2004
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"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.
Nov 08 2004