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
CCing Martin Nowak, author of the current iteration of cycle detection code: https://github.com/D-Programming-Language/druntime/commit/e07f159a98b51a22f4a1b4484119f1b4fc7e5b26
Comment #2 by code — 2013-10-01T13:32:53Z
Didn't saw the CC, I'll have a look.
Comment #3 by code — 2014-05-12T21:37:45Z
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