Closed
Description
What version of Go are you using (go version
)?
1.18
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
GO111MODULE="auto" GOARCH="amd64" GOBIN="" GOCACHE="/Users/jesseduffieldduffield/Library/Caches/go-build" GOENV="/Users/jesseduffieldduffield/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/jesseduffieldduffield/.gvm/pkgsets/go1.18/global/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/jesseduffieldduffield/.gvm/pkgsets/go1.18/global" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/Users/jesseduffieldduffield/.gvm/gos/go1.18" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/Users/jesseduffieldduffield/.gvm/gos/go1.18/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.18" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/jesseduffieldduffield/repos/list/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d_/3fryg6d934l7jxttrz1z21bh0000gn/T/go-build1796431560=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
https://go.dev/play/p/AP_5oYMfmUh
package main
import (
"fmt"
"golang.org/x/exp/slices"
)
func main() {
slice := []int{1, 1, 2}
output := slices.Compact(slice)
fmt.Printf("%v\n", output) // outputs [1 2] (expected)
fmt.Printf("%v\n", slice) // outputs [1 2 2] (not expected)
}
What did you expect to see?
Expected both the resultant slice and the output slice to be [1 2]
What did you see instead?
Resultant slice is [1 2 2]
If this is expected behaviour, it would be good to specify in the docs that the original slice should not be used after calling this function and that instead you should only use the output slice.