Cyclic depency with class static ctor

BCS BCS at pathlink.com
Fri Oct 27 09:31:54 PDT 2006


Walter Bright wrote:
> 
> Yes. It isn't possible for the language to really determine the 
> dependencies, so it plays it safe and tries to get all the static ctors 
> run before the module(s) static ctors that import them. With cyclic 
> imports and static ctors in those cycles, this is not possible.

If the rules were changed so that static this functions may only depend 
on modules imported before them, then a lot of cases could be made to work.

<code name="a.d>
static this(){writef("A\n");}
</code>

<code name="b.d>
import a;
import c;
static this(){writef("B\n");}
</code>

<code name="c.d>
import a;
static this(){writef("C\n");}
import b;
</code>

<output>
A
C
B
</output>



More information about the Digitalmars-d mailing list