immutable promise broken in unions?

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 2 04:08:48 PST 2016


On Saturday, 2 January 2016 at 12:07:31 UTC, John Colvin wrote:
> You are manually breaking immutable by making a union of 
> immutable and mutable data and then writing to the mutable 
> reference. This is roughly equivalent to casting away immutable 
> and then writing to the reference. It's a bug in your code.
>
> All references to the same data should be
> 1) either immutable or const
> or all the references should be
> 2) either mutable or const (assuming the data was never 
> immutable).
> Anything else is dangerous.

Surely the compiler should disallow this. It makes it trivial to 
break the type system otherwise.


More information about the Digitalmars-d-learn mailing list