There is an unwanted behaviour when using an invariant storage class within a struct/class. ------------------------------------------------------------------------ import std.stdio; struct MyStruct { int x = 1; invariant int y = 2; //void resety() { y = 3; }; //error: constant y is not an lvalue - as expected /* alternatives, that work as expected: const int y = 2; static invariant int y = 2; final int y = 2; //but this takes up storage for each instance */ } void main() { MyStruct mystruct; mystruct.x = 1; //ok //mystruct.y == 1, expected: 2 //mystruct.y = 2; //no error, but mystruct.x also becomes 2 writefln("mystruct.sizeof: %s mystruct.x: %s mystruct.y: %s", mystruct.sizeof, mystruct.x, mystruct.y); }
This was fixed in DMD2.022 or earlier.