Cyclic Dependencies

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Dec 9 07:20:22 PST 2008


On Tue, Dec 9, 2008 at 9:52 AM, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
> I'm not sure about this problem.  I've not encountered it, but it sounds
> weird that it would cause a runtime error...

It is weird.

====[a.d]====
module a;
import b;
static this(){}
void main(){}

====[b.d]====
module b;
import a;
static this(){}

====[Command line]====
$ rebuild a
$ ./a
object.Exception: Cyclic dependency in module a
$

If two modules circularly import each other and they both have static
ctors - regardless of whether or not those ctors really are circularly
dependent - you get an error at runtime.  Why it can't determine this
at compile time, I don't know.  Why it's an error when there's
obviously no cyclic dependency, I don't know.

http://d.puremagic.com/issues/show_bug.cgi?id=2457


More information about the Digitalmars-d-learn mailing list