On Saturday, 2 January 2016 at 12:08:48 UTC, Meta wrote:
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.
Casting away immutable can sometimes be necessary (e.g. when
talking to other languages), so I'm not sure it should be
disallowed, but it'd be great if it was somehow easier to catch
these bugs.