[Bug 66] New: Bad length in value of T[a..b] = scalar

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 22 03:37:38 PST 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=66

           Summary: Bad length in value of T[a..b] = scalar
           Product: D
           Version: 0.150
          Platform: PC
               URL: http://www.digitalmars.com/drn-
                    bin/wwwnews?digitalmars.D.bugs/1725
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: smjg at iname.com


When a slice is assigned by a scalar, the value of the assignment expression
has the length of the whole array, not that of the slice.

----------
import std.stdio;

void show(int[] s) {
    foreach (int i; s) {
        writef("%d ", i);
    }
    writefln();
}

void main() {
    int[] qwert = new int[6];
    int[] yuiop;
    yuiop = qwert[2..5] = 3;
    show(yuiop);
    show(qwert[2..5] = 4);
    show(qwert[2..5]);
    show(qwert);
    show(yuiop[2..5] = qwert[1..4]);

    yuiop = qwert[2..5];
    show(yuiop[1..3] = 6);
    writefln((yuiop[1..3] = 7).length);
}
----------

Output:

3 3 3 0 0 0
4 4 4 0 0 0
4 4 4
0 0 4 4 4 0
0 4 4
6 6 4
3

Expected output:

3 3 3
4 4 4
4 4 4
0 0 4 4 4 0
0 4 4
6 6
2

A testcase (array_chain.d) is also included in my DStress contribution
apparently still waiting to be added (see bug 63).


-- 




More information about the Digitalmars-d-bugs mailing list