[Issue 19620] New: Not quite sure what immutability means

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 26 18:07:13 UTC 2019


          Issue ID: 19620
           Summary: Not quite sure what immutability means
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dlang.org
          Assignee: nobody at puremagic.com
          Reporter: porton at narod.ru

https://dlang.org/spec/const3.html is not quite clear on what immutability
means. If a value of an immutable object changes before the immutable-specified
var appears, is it legal?


char[] a = new char[2];
a[0] = 'x';
a[1] = 'y';
immutable char[] b = cast(immutable char[]) a; // here we have an immutable
object which was modified previously

Is the above code legal?

Need to say it in the specification explicitly.


More information about the Digitalmars-d-bugs mailing list