Bug 16583 – Static module ctor semantic proposition

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-10-03T20:52:00Z
Last change time
2016-11-07T18:00:22Z
Assigned to
nobody
Creator
b2.temp

Comments

Comment #0 by b2.temp — 2016-10-03T20:52:27Z
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;} }
Comment #4 by b2.temp — 2016-11-07T18:00:22Z