-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Proposal-Accepted
Milestone
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.
alvarolm, josharian, drakmaniso, hnes, jmank88 and 32 morepascaldekloe
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.Proposal-Accepted