order of static constructor execution

Don nospam at nospam.com
Fri Mar 12 00:59:55 PST 2010


BCS wrote:
> Hello Walter,
> 
>> 2. If a loop is detected, rather than issuing an error message, simply
>> arbitrarily pick one order and continue constructing.
> 
> How about a way to explicitly cut edges in the graph (tagging imports 
> with "pragma(nodep)" or "@nodep" for instance)? That has the same end 
> effect but for only a little more work, removes any non-determinism and 
> allows for easy control of how things are resolved.

I agree. Seems to me that if a circular import exists, it's really 
something that the programmer needs to think about, and so it's 
reasonable for it to be explicit.

A really harsh solution would be:

pragma(nodependency, somepackage.somemodule);

The compiler could check that somepackage.somemodule actually defines a 
static constructor. And it could even check that a circular import 
situation actually exists. This would force the pragma to be maintained 
correctly.



More information about the Digitalmars-d mailing list