Comment #0 by snarwin+bugzilla — 2023-08-22T19:03:58Z
As of DMD 2.104.0, the following program compiles and runs to completion:
---
import core.stdc.stdio: printf;
immutable int n;
shared static this()
{
n = 123;
printf("n = %d\n", n);
}
shared static this()
{
n = 456;
printf("n = %d\n", n);
}
void main() {}
---
When run, the output is:
---
n = 123
n = 456
---
Since it should not be possible to mutate an immutable variable after it has been initialized, the second static constructor is invalid, and should be rejected by the compiler.
Comment #1 by robert.schadek — 2024-12-13T19:30:32Z