[Issue 24449] New: immutable data can be mutated after initialization in shared static constructor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Mar 23 21:59:12 UTC 2024
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 at puremagic.com
Reporter: nick at 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
}
}
--
More information about the Digitalmars-d-bugs
mailing list