Skip to content

Commit 2a5d226

Browse files
committed
[spec/arrays] Improve Assignment and Copying docs
Add Static Array Assignment subheading. State when a RangeError is thrown. Reword Array Copying summary and mention implicit conversion. Add short rationale for throwing RangeError.
1 parent b8dddee commit 2a5d226

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

spec/arrays.dd

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ assert(a is b);
187187
using pointer $(RELATIVE_LINK2 slicing, slicing), so that the number of elements
188188
to copy is then known.)
189189

190+
191+
$(H3 $(LNAME2 static-array-assign, Static Array Assignment))
192+
190193
$(P A static array can be assigned from a dynamic array - the data is copied.
191-
The lengths must match:)
194+
If the lengths do not match at runtime, a `RangeError` is thrown:)
192195

193196
$(SPEC_RUNNABLE_EXAMPLE_RUN
194197
---
@@ -352,12 +355,10 @@ i = bar[$-1]; // retrieves last element of the array
352355

353356
$(H2 $(LNAME2 array-copying, Array Copying))
354357

355-
$(P When the slice operator appears as the left-hand side of an
356-
assignment expression, it means that the contents of the array are the
357-
target of the assignment rather than a reference to the array.
358-
Array copying happens when the left-hand side is a slice, and the
359-
right-hand side is an array of or pointer to the same type.
360-
)
358+
$(P When a slice expression is the left-hand side of an
359+
assignment expression, it means that the contents of the slice are the
360+
target of the assignment rather than an array reference.
361+
The right-hand side must implicitly convert to an array type.)
361362

362363
$(SPEC_RUNNABLE_EXAMPLE_RUN
363364
---------
@@ -382,6 +383,11 @@ assert(a == [2, 0]);
382383
---------
383384
)
384385

386+
$(P If the number of elements does not match at runtime, a `RangeError` is thrown.)
387+
388+
$(RATIONALE Indexing past the end of a slice is a programming error.)
389+
390+
385391
$(H3 $(LNAME2 overlapping-copying, Overlapping Copying))
386392

387393
$(P Overlapping copies are an error:)

0 commit comments

Comments
 (0)