Bug 24099 – Immutable module variable can be initialized by multiple static constructors

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-08-22T19:03:58Z
Last change time
2024-12-13T19:30:32Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: dmd#20323 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20323 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB