Closed
Description
Currently, it's possible to convert from an array or array pointer to a slice, but there's no way of reversing this. A possible syntax could be similar to the current notation for type assertions: ArrayAssertion = "." "[" Expression ":" Expression "]" . where the operands either side of the ":" are constant expressions. One motivation for doing this is that using an array pointer allows the compiler to range check constant indices at compile time. a function like this: func foo(a []int) int { return a[0] + a[1] + a[2] + a[3]; } could be turned into: func foo(a []int) int { b := a.[0:4]; return b[0] + b[1] + b[2] + b[3]; } allowing the compiler to check all the bounds once only and give compile-time errors about out of range indices.