immutable struct/class is mutable!

Jonathan M Davis jmdavisProg at gmx.com
Mon Jul 15 18:24:21 PDT 2013


On Monday, July 15, 2013 21:08:03 Dicebot wrote:
> On Monday, 15 July 2013 at 18:39:08 UTC, JS wrote:
> > and immutability doesn't nest. immutable struct A { struct B {
> > }}, struct B is mutable.
> 
> What I have meant by "may be intended behavior" is that immutable
> qualifier does not attach at aggregate definitions. At all. It is
> irrelevant to the fact if B is nested or not.

Yes. Attributes such as immutable or private have no effect on structs or 
classes, just their members. It's a bit weird that way, but that's the way 
that it works.

> However, I have just checked and adding a member field to B also
> leaves it mutable. And that is really frustrating.

That definitely sounds like a bug.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list