Skip to content

affected/package: golang.org/x/exp/slices#Compact #51788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jesseduffield opened this issue Mar 18, 2022 · 1 comment
Closed

affected/package: golang.org/x/exp/slices#Compact #51788

jesseduffield opened this issue Mar 18, 2022 · 1 comment

Comments

@jesseduffield
Copy link

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.

@seankhliao
Copy link
Member

I believe it already does:

Compact modifies the contents of the slice s; it does not create a new slice.

@golang golang locked and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants