March 23 [Issue 24449] New: immutable data can be mutated after initialization in shared static constructor | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24449 Issue ID: 24449 Summary: immutable data can be mutated after initialization in shared static constructor Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: nick@geany.org import std.stdio; immutable int x; shared static this() { x = 5; // OK, initialization not assignment x.writeln(); // 5 x = 6; // should error x++; // should error assert(x == 7); } It should not be possible to assign immutable data after it is initialized in the shared static constructor. That would make those consistent with class constructors: class C { immutable int x; this() { x = 5; x = 6; // error, x initialized multiple times } } -- |
Copyright © 1999-2021 by the D Language Foundation