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/maps: Clone does not preserve nil #53817

Closed
icholy opened this issue Jul 12, 2022 · 2 comments
Closed

x/exp/maps: Clone does not preserve nil #53817

icholy opened this issue Jul 12, 2022 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@icholy
Copy link

icholy commented Jul 12, 2022

The x/exp/maps.Clone function doesn't preserve nil the way x/exp/slices.Clone does.

package main

import (
	"fmt"

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

func main() {
	var m map[string]int
	fmt.Printf("%#v\n", m)             // map[string]int(nil)
	fmt.Printf("%#v\n", maps.Clone(m)) // map[string]int{}
}

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

$ go version
go version go1.18.3 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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/icholy/.cache/go-build"
GOENV="/home/icholy/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/icholy/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/icholy/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4044300034=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Cloned a nil map using x/exp/maps.Clone.

What did you expect to see?

The cloned map is also nil

What did you see instead?

The cloned map is an empty non-nil map.

@gopherbot gopherbot added this to the Unreleased milestone Jul 12, 2022
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 12, 2022
@mknyszek
Copy link
Contributor

CC @ianlancetaylor

@gopherbot
Copy link

Change https://go.dev/cl/417274 mentions this issue: x/exp/maps: Clone preserve nil in case it matters.

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 13, 2022
@golang golang locked and limited conversation to collaborators Jul 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants