[Issue 2457] Detecting circular module dependencies at compile time
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 16 11:54:10 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2457
------- Comment #2 from jarrett.billingsley at gmail.com 2008-11-16 13:54 -------
====[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
$
Pretty short.
It makes no sense that the compiler would output an executable that will always
cause a runtime error. The compiler knows that there is a circular module
dependency, and should be able to issue an error at compile time.
Note, however, that in this case there _is_ no circular dependency. Even
though the modules are circularly imported and both have static constructors,
the static constructors do not depend on the other module. This _should_ be
legal, at least semantically. That the program issues an error means that the
compiler and runtime aren't doing a whole lot of analysis to determine that
there is a cyclic dependency. It's a false positive.
--
More information about the Digitalmars-d-bugs
mailing list