You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 {}
The text was updated successfully, but these errors were encountered:
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:
Trying to use the array as map key results in a panic:
The text was updated successfully, but these errors were encountered: