gopls version
x/tools/gopls v0.18.1
go env
What did you do?
This program prints [1 4]
package main
import (
"fmt"
)
func main() {
counter := 0
getSlice := func() []int {
counter++
return []int{counter, counter + 1, counter + 2}
}
fmt.Println(append(getSlice()[:1], getSlice()[2:]...))
}
What did you see happen?
Gopls wants to modernize append(getSlice()[:1], getSlice()[2:]...) -> slices.Delete(getSlice(), 1, 2).
Since the two calls to getSlice() are replaced by one, the final output is replaced by [1 3].
What did you expect to see?
Behavior unchanged.
Editor and settings
No response
Logs
No response