On 1/11/21 6:52 PM, Paul Backus wrote:
On Monday, 11 January 2021 at 16:10:49 UTC, Steven Schveighoffer wrote:
There are some... odd rules.
struct S
{
[...]
immutable int e = 5; // stored in data segment, not per instance!
Are you sure?
struct S
{
immutable int n = 123;
this(int n) { this.n = n; }
}
void main()
{
S s1;
S s2 = 456;
assert(s1.n == 123);
assert(s2.n == 456);
}
Yes, I was sure, but clearly wrong ;)
Hm... I guess it was changed! Deprecated in 2.065 [1] and finally
changed in 2.067 [2]
Now you need static immutable to make it not part of the instance. Which
makes sense (score 1 for consistency!)
-Steve
[1] https://dlang.org/changelog/2.065.0.html#staticfields2
[2] https://issues.dlang.org/show_bug.cgi?id=3449