Subslice
The subslice postfix operation indexes a range of a slice value, returning a new slice spanning that range. The start index is inclusive; the end index is exclusive.
Process
At runtime:
- the operand is evaluated;
- the start index expression is evaluated;
- the end index expression is evaluated; and
- the slice of the operand's elements from the start index, inclusive, up to the end index, exclusive, is the subslice's result.
For a start or end index outside the slice's range, or a start index greater than the end index, is a runtime error; the compiler emits runtime logic to detect it, unless it can be proven that the indices are within range and the start index does not exceed the end index. A negative index value is always out of range.
See the runtime error model on the architecture page.
Assertions
- The operand's type is a slice type.
- Each index expression has an integer type, signed or unsigned.
- The subslice has the operand's slice type.
Syntax
subslice_operation = left_bracket, expression, comma, expression, right_bracket ;