digitalmars.D.bugs - [Bug 66] New: Bad length in value of T[a..b] = scalar
- d-bugmail puremagic.com (58/58) Mar 22 2006 http://d.puremagic.com/bugzilla/show_bug.cgi?id=66
- d-bugmail puremagic.com (13/13) Apr 03 2006 http://d.puremagic.com/bugzilla/show_bug.cgi?id=66
- d-bugmail puremagic.com (9/9) Apr 04 2006 http://d.puremagic.com/bugzilla/show_bug.cgi?id=66
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 digitalmars.com
ReportedBy: smjg 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).
--
Mar 22 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=66
deewiant gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Fixed in 0.151.
Also, unless I'm mistaken, there is a bug in that test code: you have
"show(yuiop[2..5] = qwert[1..4]);" at a point where yuiop's length is 3.
Shouldn't that read "show(yuiop = qwert[1..4]);"? I get your expected output
after that change.
--
Apr 03 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=66
You're right that the testcase is buggy. However, the point was to compare the
behaviour when copying a slice to a slice, whereas your proposed change turns
it into a reference assignment.
A better corretion is simply to add
yuiop.length = 6;
before that line.
--
Apr 04 2006









d-bugmail puremagic.com 