immutable promise broken in unions?
Marc Schütz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 2 04:21:54 PST 2016
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.
Right, this is a known bug:
https://issues.dlang.org/show_bug.cgi?id=13537
More information about the Digitalmars-d-learn
mailing list