how to avoid "cycle detected"?

Kapps via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 2 10:21:01 PDT 2015


On Wednesday, 1 July 2015 at 09:09:53 UTC, aki wrote:
> Following code causes run-time error.
> How can I use static this() without causing error?
> It's difficult to avoid this situation because
> actual code is more complex.
>
> file main.d:
> void main() {
> }
>
> file a.d:
> import b;
> class A {
> 	static this() {}
> };
>
> file b.d:
> import a;
> class B {
> 	static this() {}
> };
>
> object.Exception at src\rt\minfo.d(162): Aborting: Cycle detected 
> between modules w
> ith ctors/dtors:
> a -> b -> a

An ugly solution, but the approach used in Phobos is to create 
something like a_init.d which a.d imports, provided that the 
static ctors don't actually rely on things from the static ctor 
of b.



More information about the Digitalmars-d-learn mailing list