bearophile wrote:
This is a reduced version of a D2 program, written while I was trying
to use/learn immutability. This program compiles:


struct Foo { static int x; } void main() { immutable Foo f; Foo.x++; f.x++; }


My idea was that immutable applied to a struct makes every thing in
such struct namespace immutable. I was wrong, but what do you think
about changing a little how D works here? A possible idea is: if one
instance is 'const', then the static attribute x is seen as const
from just that instance. If one instance is set to 'immutable' as
here, then the static attributes become immutable in every instance
of Foo.

I think that's unworkable, as static variables cannot immutable in one instance and mutable in another.

Reply via email to