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

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-03-22T05:37:00Z
Last change time
2014-02-15T02:09:18Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
smjg

Comments

Comment #0 by smjg — 2006-03-22T05:37:38Z
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).
Comment #1 by matti.niemenmaa+dbugzilla — 2006-04-03T06:00:11Z
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.
Comment #2 by smjg — 2006-04-04T06:22:32Z
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.