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

reflect: potential change required in DeepEqual #37897

Closed
obourdon opened this issue Mar 17, 2020 · 4 comments
Closed

reflect: potential change required in DeepEqual #37897

obourdon opened this issue Mar 17, 2020 · 4 comments

Comments

@obourdon
Copy link

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

$ go version
go version go1.13.7 darwin/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="/Users/XXX/Library/Caches/go-build"
GOENV="/Users/XXX/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/XXX/.gvm/pkgsets/go1.13.7/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/XXX/.gvm/gos/go1.13.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/XXX/.gvm/gos/go1.13.7/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/XXX/Documents/WORK/SquareScale/HASHICORP/terraform-provider-aws/go.mod"
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=/var/folders/k0/35x3347j4s18t_h4z932f3nr0000gn/T/go-build598493337=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

See issue # 11059 in Terraform AWS Provider

and more specifically this part

DeepEqual fails because of the following item which is however perfectly identical in both cases:

 F: (schema.SchemaSetFunc) 0x4ec7530,

What did you expect to see?

If pointer addresses are identical true should be returned so something like:

	case Func:
		if v1.IsNil() && v2.IsNil() {
			return true
		}
		// Can't do better than this:
		return v1 == v2

might be better (IMHO)

What did you see instead?

DeepEqual returns false

@obourdon
Copy link
Author

After reading a bit more about function comparison, which does not seem very obvious, may be we could just parameterize the DeepEqual call so that this check can be disabled ? Just wondering ...

@obourdon obourdon changed the title Potential issue with reflect.DeepEqual code Potential change required in reflect.DeepEqual code Mar 17, 2020
@gbbr gbbr changed the title Potential change required in reflect.DeepEqual code reflect: potential change required in DeepEqual Mar 17, 2020
@bcmills
Copy link
Contributor

bcmills commented Mar 17, 2020

Per https://golang.org/ref/spec#Comparison_operators:

Slice, map, and function values are not comparable. However, as a special case, a slice, map, or function value may be compared to the predeclared identifier nil.

And per the reflect.DeepEqual documentation:

Func values are deeply equal if both are nil; otherwise they are not deeply equal.

Any change to that behavior would violate the Go 1 compatibility policy.

@ianlancetaylor
Copy link
Member

Sorry, we aren't going to make this change in reflect.DeepEqual. There are many possible ways of doing equality comparisons. DeepEqual is one of them. Many people find it useful, but there are many possible variants. We don't want to try to provide all those variants. You can use DeepEqual as a template for your own equality function.

@obourdon
Copy link
Author

@ianlancetaylor @bcmills many thanks for this feedback, I fully understand.Many thanks again

@golang golang locked and limited conversation to collaborators Mar 18, 2021
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

4 participants