I've not used static constructors before, but it seems like the following should not be allowed:
import std.stdio;
immutable int x;
@safe shared static this()
{
x.writeln(); // 0
x = 5;
x.writeln(); // 5
x = 6;
x++;
assert(x == 7);
}
Should I file a bug to require that x
is only written to once? That would make it consistent with class constructors:
class C
{
immutable int x;
this()
{
x = 5;
x = 6; // error, x initialized multiple times
}
}