Skip to content

Commit e620bc7

Browse files
committed
Extend Copying example with dynamic array
1 parent 8550c6c commit e620bc7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

spec/arrays.dd

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,26 @@ $(H2 $(LNAME2 array-copying, Array Copying))
359359
right-hand side is an array of or pointer to the same type.
360360
)
361361

362-
$(SPEC_RUNNABLE_EXAMPLE_FAIL
362+
$(SPEC_RUNNABLE_EXAMPLE_RUN
363363
---------
364-
int[3] s;
365-
int[3] t;
364+
int[3] s, t;
365+
int[] a;
366366

367367
s = t; // the 3 elements of t are copied into s
368368
s[] = t; // the 3 elements of t are copied into s
369369
s[] = t[]; // the 3 elements of t are copied into s
370370
s[1..2] = t[0..1]; // same as s[1] = t[0]
371371
s[0..2] = t[1..3]; // same as s[0] = t[1], s[1] = t[2]
372-
s[0..4] = t[0..4]; // error, only 3 elements in s
373-
s[0..2] = t; // error, operands have different lengths
372+
//s[0..4] = t[0..4]; // error, only 3 elements in s and t
373+
//s[0..2] = t; // error, operands have different lengths
374+
375+
a = [1, 2];
376+
s[0..2] = a;
377+
assert(s == [1, 2, 0]);
378+
379+
//a[] = s; // RangeError, lengths don't match
380+
a[0..2] = s[1..3];
381+
assert(a == [2, 0]);
374382
---------
375383
)
376384

0 commit comments

Comments
 (0)