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

runtime: array of type [8]interface{} is not comparable or hashable #18652

Closed
jellevandenhooff opened this issue Jan 13, 2017 · 5 comments
Closed
Milestone

Comments

@jellevandenhooff
Copy link
Contributor

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

go version go1.7.1 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jelle/hack/backend/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.1/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8s/_2n6vtf514ddk4vc8vw3l2nr0000gn/T/go-build445284626=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

I created an array of type [8]interface{}, and filled the array with int(0)s. Since all elements of the array are comparable, I expected the array to be comparable (https://golang.org/ref/spec#Comparison_operators). However, it is not: Unlike an array of type [7]interface{} or an array of type [8]int, the array of type [8]interface{} is not comparable or hashable. See https://play.golang.org/p/aVgVglrGQS.

For context, the array of type [8]interface{} was created as a cache key for calls to sql/db.Query. A small wrapper converts the arguments to sql/db.Query into an interface array to use as key in a map[interface{}]interface{} holding previously fetched results.

What did you expect to see?

I expected the playground program to compile and run, without panicing even when uncommenting the comparison of the [8]interface{} value.

What did you see instead?

Comparing the array of [8]interface{} results in a compile-time error:

# command-line-arguments
main.main: call to external function type..eq.[8]interface {}
main.main: type..eq.[8]interface {}: not defined
main.main: undefined: type..eq.[8]interface {}

Trying to use the array as map key results in a panic:

panic: runtime error: hash of unhashable type [8]interface {}
@bradfitz
Copy link
Contributor

/cc @randall77 @mdempsky

@bradfitz bradfitz added this to the Go1.9 milestone Jan 13, 2017
@ALTree
Copy link
Member

ALTree commented Jan 13, 2017

Dup of #17752

@randall77
Copy link
Contributor

Yes, this should be fixed in 1.8. @jellevandenhooff , can you try the 1.8 release candidate?

@bradfitz
Copy link
Contributor

Ah, indeed. I can reproduce that it's fixed in Go 1.8 but broken in Go 1.7.

@jellevandenhooff
Copy link
Contributor Author

jellevandenhooff commented Jan 13, 2017

Thanks, 1.8rc1 works, also for much bigger arrays.

@golang golang locked and limited conversation to collaborators Jan 13, 2018
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

5 participants