Proposal Details
When calling slices.Delete, shadowing the slice variable is almost certainly a bug:
s := slices.Delete(s, 2, 3) // !! accidentally using := instead of = !!
Playground
Why
Shadowing comes with surprises when used accidentally. In general, vet cannot warn about it because it does not know if a specific use of shadowing is intentional and legit, or not.
Shadowing keeps the original var intact, so it can be reused outside of the current inner scope where the new var is declared. In the specific case of Delete (and friends), we know that reusing the original value is not desirable:
"When calling these functions (Delete. etc.) we must consider the original slice invalid"
I am not aware of any such shadowing that would be legit and useful. If they do exist, the vet warning would be easy to work around by choosing a different var identifier (no shadowing).
On the other hand, I am very aware of the nasty bugs caused by accidental shadowing in general, and by accidental shadowing in the case of slices.Delete and friends.
Suggestion
vet warning:
./prog.go:11:14: shadowing slice 's' on call to slices.Delete
Same for the friends DeleteFunc, Compact, CompactFunc, Replace.
Like #62729, the goal is to minimize the risks associated with incorrectly using the slices package API.
Proposal Details
When calling
slices.Delete, shadowing the slice variable is almost certainly a bug:Playground
Why
Shadowing comes with surprises when used accidentally. In general, vet cannot warn about it because it does not know if a specific use of shadowing is intentional and legit, or not.
Shadowing keeps the original var intact, so it can be reused outside of the current inner scope where the new var is declared. In the specific case of Delete (and friends), we know that reusing the original value is not desirable:
"When calling these functions (Delete. etc.) we must consider the original slice invalid"
I am not aware of any such shadowing that would be legit and useful. If they do exist, the vet warning would be easy to work around by choosing a different var identifier (no shadowing).
On the other hand, I am very aware of the nasty bugs caused by accidental shadowing in general, and by accidental shadowing in the case of slices.Delete and friends.
Suggestion
vet warning:
Same for the friends DeleteFunc, Compact, CompactFunc, Replace.
Like #62729, the goal is to minimize the risks associated with incorrectly using the
slicespackage API.