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: panic with an embedded type param #43759

Open
tenntenn opened this issue Jan 18, 2021 · 5 comments
Open

cmd/go2go: panic with an embedded type param #43759

tenntenn opened this issue Jan 18, 2021 · 5 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tenntenn
Copy link
Contributor

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

$ go version
go version devel +79f7966688 Tue Jan 12 16:41:23 2021 +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/tenntenn/Library/Caches/go-build"
GOENV="/Users/tenntenn/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tenntenn/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/tenntenn/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/gotip/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/usr/local/gotip/src/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/gh/r3m72st579d1z1trbmd6xfyc0000gp/T/go-build686441710=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

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

package main

import (
	"fmt"
)

type C[T any] interface {
	type struct{ T }
}

func f[T any, _ C[T]](v T) {
	fmt.Println(v)
}

func main() {
	f(10)
}

What did you expect to see?

Print 10.

What did you see instead?

Panic.

panic: /var/folders/gh/r3m72st579d1z1trbmd6xfyc0000gp/T/go2go-run128067254/main.go2:12:2: unexpected type string character '=' in "struct{T /* = int */}"

goroutine 1 [running]:
go/go2go.(*translator).instantiatedName(0xc00014f678, 0x0, 0xc00000c4c0, 0xc00000c740, 0x2, 0x2, 0xc000061aa8, 0x0, 0x0, 0x0)
	/usr/local/gotip/src/go/go2go/names.go:62 +0x765
go/go2go.(*translator).instantiateFunction(0xc00014f678, 0x0, 0xc00000c4c0, 0xc00000c840, 0x2, 0x2, 0xc00000c740, 0x2, 0x2, 0x124c200, ...)
	/usr/local/gotip/src/go/go2go/instantiate.go:94 +0x85
go/go2go.(*translator).translateFunctionInstantiation(0xc00014f678, 0xc000048660)
	/usr/local/gotip/src/go/go2go/rewrite.go:906 +0x46e
go/go2go.(*translator).translateExpr(0xc00014f678, 0xc000048660)
	/usr/local/gotip/src/go/go2go/rewrite.go:687 +0x3cc
go/go2go.(*translator).translateStmt(0xc00014f678, 0xc000048670)
	/usr/local/gotip/src/go/go2go/rewrite.go:578 +0x3ac
go/go2go.(*translator).translateBlockStmt(0xc00014f678, 0xc000010db0)
	/usr/local/gotip/src/go/go2go/rewrite.go:547 +0x57
go/go2go.(*translator).translateFuncDecl(0xc00014f678, 0xc000020560)
	/usr/local/gotip/src/go/go2go/rewrite.go:538 +0xdb
go/go2go.(*translator).translate(0xc00014f678, 0xc00007c120)
	/usr/local/gotip/src/go/go2go/rewrite.go:466 +0x391
go/go2go.rewriteAST(0xc0000202c0, 0xc0000543c0, 0x0, 0x0, 0xc00005f770, 0xc00007c120, 0x14ac201, 0xc000020300, 0x140b480)
	/usr/local/gotip/src/go/go2go/rewrite.go:257 +0xe5
go/go2go.rewriteFile(0xc0000160f0, 0x43, 0xc0000202c0, 0xc0000543c0, 0x0, 0x0, 0xc00005f770, 0xc000016280, 0x4c, 0xc00007c120, ...)
	/usr/local/gotip/src/go/go2go/rewrite.go:221 +0xb8
go/go2go.rewriteFilesInPath(0xc0000543c0, 0x0, 0x0, 0xc0000160f0, 0x43, 0xc000048490, 0x1, 0x1, 0x0, 0x0, ...)
	/usr/local/gotip/src/go/go2go/go2go.go:115 +0xc5c
go/go2go.rewriteToPkgs(0xc0000543c0, 0x0, 0x0, 0xc0000160f0, 0x43, 0xc0000101d0, 0xc0000160f0, 0x43, 0x7ffeefbffb79, 0x8)
	/usr/local/gotip/src/go/go2go/go2go.go:46 +0x165
go/go2go.Rewrite(...)
	/usr/local/gotip/src/go/go2go/go2go.go:30
main.translate(0xc0000543c0, 0xc0000160f0, 0x43)
	/usr/local/gotip/src/cmd/go2go/translate.go:15 +0x47
main.main()
	/usr/local/gotip/src/cmd/go2go/main.go:63 +0xb2f
@tenntenn
Copy link
Contributor Author

I tried adding = to nameCodes, it works.

diff --git a/src/go/go2go/names.go b/src/go/go2go/names.go
index ec3bef2db7..c054fb5a93 100644
--- a/src/go/go2go/names.go
+++ b/src/go/go2go/names.go
@@ -34,8 +34,9 @@ var nameCodes = map[rune]int{
 	'<':       11,
 	'-':       12,
 	'/':       13,
-	nameSep:   14,
-	nameIntro: 15,
+	'=':       14,
+	nameSep:   15,
+	nameIntro: 16,
 }
 
 // instantiatedName returns the name of a newly instantiated function.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 18, 2021
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jan 18, 2021
@ianlancetaylor
Copy link
Contributor

CC @griesemer

I'm not sure where the /* = int */ is coming from.

In general the go2go playground does not have good support for embedded type parameters.

@tenntenn
Copy link
Contributor Author

/* = int */ comes from types.WriteType.

@findleyr
Copy link
Contributor

I'm working on updating the playground this week; I can take a look at this particular panic.

@findleyr findleyr self-assigned this Jan 19, 2021
@KeKe-Li
Copy link

KeKe-Li commented Jan 22, 2021

also i have the same prombles,but i think is just embedded type parameters not have good support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants