Skip to content
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

x/exp/slices: Clone returns nil for an empty non-nil slice #49660

Closed
ainar-g opened this issue Nov 18, 2021 · 2 comments
Closed

x/exp/slices: Clone returns nil for an empty non-nil slice #49660

ainar-g opened this issue Nov 18, 2021 · 2 comments

Comments

@ainar-g
Copy link
Contributor

ainar-g commented Nov 18, 2021

What version of Go are you using (go version)?

$ go version
go version devel go1.18-5337e53dfa Sun Nov 14 17:38:42 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ainar/.cache/go-build"
GOENV="/home/ainar/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ainar/go/pkg/mod"
GONOPROXY="REMOVED"
GONOSUMDB="REMOVED"
GOOS="linux"
GOPATH="/home/ainar/go"
GOPRIVATE="REMOVED"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/ainar/go/tip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/ainar/go/tip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-5337e53dfa Sun Nov 14 17:38:42 2021 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3251505622=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"

	"golang.org/x/exp/slices"
)

func main() {
	fmt.Printf("%#v\n", slices.Clone([]int(nil)))
	fmt.Printf("%#v\n", slices.Clone([]int{}))
	fmt.Printf("%#v\n", slices.Clone([]int{1}))
}

What did you expect to see?

[]int(nil)
[]int{}
[]int{1}

What did you see instead?

[]int(nil)
[]int(nil)
[]int{1}
@gopherbot gopherbot added this to the Unreleased milestone Nov 18, 2021
@gopherbot
Copy link

Change https://golang.org/cl/365174 mentions this issue: slices: preserve nil/non-nil in Clone

@ainar-g
Copy link
Contributor Author

ainar-g commented Nov 22, 2021

I confirm that the fix works, thanks!

@golang golang locked and limited conversation to collaborators Nov 22, 2022
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

2 participants