You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for the Delete and Replace functions states
// ... Delete panics if s[i:j] is not a valid slice of s. ...
// ... Replace panics if s[i:j] is not a valid slice of s. ...
and the documentation within the body of the functions reinforces the meaning of "valid slice of s":
_ = s[i:j] // verify that i:j is a valid subslice
However, the functions will also panic if s[i:j] is a valid slice of s, which occurs when len(s) < j <= cap(s). For instance:
s := []string{"a", "b", "c", "d", "e"}
s = s[0:2]
_ = s[0:4] // this is a valid slice of s
slices.Delete(s, 0, 4) // panics, but s[0:4] is a valid slice of s
slices.Replace(s, 0, 4) // panics, but s[0:4] is a valid slice of s
The documentation should state:
// ... Delete panics if j > len(s) or s[i:j] is not a valid slice of s. ...
// ... Replace panics if j > len(s) or s[i:j] is not a valid slice of s. ...
The text was updated successfully, but these errors were encountered:
The documentation for the
Delete
andReplace
functions statesand the documentation within the body of the functions reinforces the meaning of "valid slice of s":
However, the functions will also panic if
s[i:j]
is a valid slice ofs
, which occurs whenlen(s) < j <= cap(s)
. For instance:The documentation should state:
The text was updated successfully, but these errors were encountered: