<div>Why can't we detect at compile time module ctor/dtor cycles (instead of runtime) ?</div><div>See example below.</div><div><br></div><div>It should be easy to detect the chain at CT:</div><div><br></div><div>algo:</div>
<div>build graph from import dependencies a=>b if module a imports module b.</div><div>mark as red the modules that have a ctor </div><div>collapse each non-red node into its parent (and update parent's edges)</div>
<div>detect cycles (eg BFS)</div><div><br></div><div>(same with dtor)</div><div><br></div><div><br></div><div>----</div><div>a1:</div><div>import a2;</div><div>void main(){}</div><div><div>static this(){}</div><div><br></div>
<div><br></div></div><div>a2:</div><div>import a3;</div><div>static this(){}</div><div><br></div><div>a3:</div><div>import a1;</div><div><div>----</div></div><div><br></div><div>rdmd --force --build-only -oftest a1 #works</div>
<div><div>./test #error:</div><div>object.Exception@src/rt/minfo.d(243): Aborting: Cycle detected between modules with ctors/dtors:</div><div>a1 -> a2 -> a3 -> a1</div></div><div><br></div>