Mutate immutable inside shared static constructor
Nick Treleaven
nick at geany.org
Sat Mar 23 21:23:23 UTC 2024
I've not used static constructors before, but it seems like the
following should not be allowed:
```d
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:
```d
class C
{
immutable int x;
this()
{
x = 5;
x = 6; // error, x initialized multiple times
}
}
```
More information about the Digitalmars-d-learn
mailing list