March 08, 2010 More on immutable | ||||
---|---|---|---|---|
| ||||
I am trying to learn more about the usage of immutable. This is a little D2 program: immutable class S { static int x; static this() { S.x = 10; } } void main() {} The compiler outputs: test.d(3): Error: function test2.S._staticCtor1 without 'this' cannot be const/immutable Can you tell me what's wrong or how I can fix it? Bye and thank you, bearophile |
March 08, 2010 Re: More on immutable | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Mon, 08 Mar 2010 09:08:26 -0500, bearophile <bearophileHUGS@lycos.com> wrote: > I am trying to learn more about the usage of immutable. This is a little D2 program: > > > immutable class S { > static int x; > static this() { > S.x = 10; > } > } > void main() {} > > > The compiler outputs: > test.d(3): Error: function test2.S._staticCtor1 without 'this' cannot be const/immutable > > Can you tell me what's wrong or how I can fix it? There was a discussion on D.learn in December of last lear that resulted in this bug being filed: http://d.puremagic.com/issues/show_bug.cgi?id=3598 Note that even if static functions were allowed in immutable classes/structs, the static field members will still be tagged as immutable, so your example shouldn't compile. -Steve |
Copyright © 1999-2021 by the D Language Foundation