bearophile wrote:
I'm playing some more with immutables in D2. This program compiles:
struct Foo {
static int x;
}
void main() {
immutable Foo f;
Foo.x++;
f.x++;
}
Is this code supposed to be correct? If I have an immutable struct I want all
of it to be immutable...
Bye and thank you,
bearophile
It is correct, because x isn't a part of the struct, it's a global
variable. However, in my opinion that last line should cause a compiler
error -- it shouldn't be possible to access static members through an
instance of the struct.
-Lars