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

cmd/go2go: cannot create a map of which key is a type parameter of a generic type. #40014

Closed
YoshikiShibata opened this issue Jul 3, 2020 · 3 comments

Comments

@YoshikiShibata
Copy link

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

$ go version
go version devel +85ed317eb2 Thu Jul 2 00:33:43 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

N/A

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/yoshiki/Library/Caches/go-build"
GOENV="/Users/yoshiki/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/yoshiki/gocode/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/yoshiki/gocode:/Users/yoshiki/exercises/gpl:/Users/yoshiki/oak"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/yoshiki/tools/go2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/yoshiki/tools/go2/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/r3/f30_9n8958j4ndrjyl1k7mp40000gn/T/go-build832033261=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version devel +85ed317eb2 Thu Jul 2 00:33:43 2020 +0000 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +85ed317eb2 Thu Jul 2 00:33:43 2020 +0000
uname -v: Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.15.5
BuildVersion:	19F101
lldb --version: lldb-1103.0.22.10
Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)

What did you do?

I tried to create a map of which key is a type parameter of a generic type.

package main

import "fmt"

type Foo(type T) struct {
}

func (f *Foo(T)) bar() {
	seen := make(map[T]bool)
	fmt.Printf("seen: %T\n", seen)
}

func main() {
	f := &Foo(int){}
	f.bar()
}

What did you expect to see?

Can compile

What did you see instead?

$ go tool go2go run map.go2
type checking failed for main
/var/folders/r3/f30_9n8958j4ndrjyl1k7mp40000gn/T/go2go-run727879803/map.go2:9:19: invalid map key type T
@tdakkota
Copy link

tdakkota commented Jul 3, 2020

T should be comparable

package main

import "fmt"

type Foo(type T comparable) struct {
}

func (f *Foo(T)) bar() {
	seen := make(map[T]bool)
	fmt.Printf("seen: %T\n", seen)
}

func main() {
	f := &Foo(int){}
	f.bar()
}

https://go2goplay.golang.org/p/mswUb5qvKUX

@ianlancetaylor
Copy link
Contributor

@tdakkota is right. I don't see a bug here.

@YoshikiShibata
Copy link
Author

I see. Thanks!

@golang golang locked and limited conversation to collaborators Jul 3, 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