[Issue 1339] New: Invariant/const-ness is broken by built-in array properties

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 12 21:41:12 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1339

           Summary: Invariant/const-ness is broken by built-in array
                    properties
           Product: D
           Version: 2.002
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: kinaba at is.s.u-tokyo.ac.jp


Here's an example:

import std.stdio;
void main() {
        invariant(int)[] x = [1,4,2,3];

        x.sort;
        writefln(x); // [1,2,3,4]

        x.reverse;
        writefln(x); // [4,3,2,1]

        x.length = x.length - 1;
        x.length = x.length + 1;
        writefln(x); // [4,3,2,0]
}

The properties .sort and .reverse should be simply disallowed for invariant
arrays. I'm not sure about the .length property, but I think some consideration
must be given...


-- 



More information about the Digitalmars-d-bugs mailing list