Bug 9881 – Indirect cyclic imports are not forbidden
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-05T03:40:00Z
Last change time
2014-05-12T21:37:45Z
Keywords
accepts-invalid
Assigned to
code
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2013-04-05T03:40:00Z
Consider a program with three files:
=== A.d ===
import B, C;
void main() {}
=== B.d ===
import A;
shared static this() {}
=== C.d ===
import A;
shared static this() {}
Illustrated:
+---+ +---+ +---+
| | ---> | | ---> | |
| B | | A | | C |
| | <--- | | <--- | |
+---+ +---+ +---+
B and C have static constructors.
This program is allowed to compile and run, even though there is a circular dependency between B and C. In a practical case, it can result in a problem when B accesses something initialized in C via something in A.
Comment #1 by dlang-bugzilla — 2013-04-05T03:57:40Z
I don't see a feasible way to resolve this problem by restricting or ordering the dependencies. Consider the following example which has the same underlying problem.
cat > a.d << CODE
__gshared Object o;
CODE
cat > b.d << CODE
import a;
shared static this() { assert(o !is null); }
CODE
cat > c.d << CODE
import a;
shared static this() { o = new Object; }
CODE
dmd -main -unittest b c -run a
dmd -main -unittest c b -run a