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).
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.
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.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル