I propose that static module constructor/destructor would only happen without selective import:
import stuff; // static module ctor triggerred
import stuff: Type; // static module ctor not triggerred
Comment #1 by code — 2016-10-31T20:38:08Z
That's doesn't make sense b/c using Type could depend on the sth. being initialized first.
What we could try is to teach the compiler to recognize a few more standalone constructors (that simply initialize plain data fields).
Comment #2 by b2.temp — 2016-11-01T09:10:26Z
(In reply to Martin Nowak from comment #1)
> That's doesn't make sense b/c using Type could depend on the sth. being
> initialized first.
> What we could try is to teach the compiler to recognize a few more
> standalone constructors (that simply initialize plain data fields).
I don't really mind but I'd say that your argument is fallacious. Why ? Because "Type" can have its own static ctor.
Comment #3 by schveiguy — 2016-11-01T13:52:51Z
module bad;
int x;
static this()
{
x = 42;
}
struct Type
{
int foo() { return x;}
}