Skip to content

[spec/arrays] Improve Assignment and Copying docs #4237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions spec/arrays.dd
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@ assert(a is b);
using pointer $(RELATIVE_LINK2 slicing, slicing), so that the number of elements
to copy is then known.)


$(H3 $(LNAME2 static-array-assign, Static Array Assignment))

$(P A static array can be assigned from a dynamic array - the data is copied.
The lengths must match:)
If the lengths do not match at runtime, a `RangeError` is thrown:)

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

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

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

$(SPEC_RUNNABLE_EXAMPLE_RUN
---------
Expand All @@ -382,6 +383,11 @@ assert(a == [2, 0]);
---------
)

$(P If the number of elements does not match at runtime, a `RangeError` is thrown.)

$(RATIONALE Indexing past the end of a slice is a programming error.)


$(H3 $(LNAME2 overlapping-copying, Overlapping Copying))

$(P Overlapping copies are an error:)
Expand Down