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: unexpected type parameter panic in translator #39953

Closed
griesemer opened this issue Jun 30, 2020 · 2 comments
Closed

cmd/go2go: unexpected type parameter panic in translator #39953

griesemer opened this issue Jun 30, 2020 · 2 comments
Assignees
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 30, 2020

Extracted from #39758: The following program

package main

type top(type T, T2) struct {
	p *parent(T, T2)
}

type parent(type T, T2) struct {
	(child(T, T2))
}

type child(type T, T2) struct {
	T2
}

func (d *top(T, T2)) foo() *T {
	// panic: internal error: receiver type parameter inference failed
	// t, _ := d.p.foo() 

	// panic: -: unexpected type string character '₇' in "T₇"
	t, _ := d.p.child.foo()
	return t
}

func (rb *child(T, T2)) foo() (*T, bool) {
	return nil, true
}

func main() {
	var _ top(int, int)
}

type-checks ok but the translator reports

$ go tool go2go run main.go2 
panic: unexpected type parameter

goroutine 1 [running]:
go/go2go.(*translator).typeToAST(0xc0001a5678, 0x12e40a0, 0xc00012ae80, 0xc00011d6e0, 0xc0001a4c78)
	/Users/gri/go/src/go/go2go/types.go:596 +0x1725
go/go2go.(*translator).typeListToASTList(0xc0001a5678, 0xc00011cf80, 0x2, 0x2, 0x0, 0x0, 0xc0001241f8, 0xc0001a4b68, 0x1003598, 0x12570c0)
	/Users/gri/go/src/go/go2go/rewrite.go:1175 +0xe5
go/go2go.(*translator).lookupInstantiatedType(0xc0001a5678, 0xc0001366c0, 0x0, 0x0, 0x0)
	/Users/gri/go/src/go/go2go/rewrite.go:1095 +0x2b6
go/go2go.(*translator).translateSelectorExpr(0xc0001a5678, 0xc00011c780)
	/Users/gri/go/src/go/go2go/rewrite.go:804 +0x5b1
go/go2go.(*translator).translateExpr(0xc0001a5678, 0xc00011c780)
	/Users/gri/go/src/go/go2go/rewrite.go:666 +0x4ba
go/go2go.(*translator).translateSelectorExpr(0xc0001a5678, 0xc00012a800)
	/Users/gri/go/src/go/go2go/rewrite.go:756 +0x71
go/go2go.(*translator).translateExpr(0xc0001a5678, 0xc00012a800)
	/Users/gri/go/src/go/go2go/rewrite.go:666 +0x4ba
go/go2go.(*translator).translateExpr(0xc0001a5678, 0xc0001046c0)
	/Users/gri/go/src/go/go2go/rewrite.go:685 +0x385
go/go2go.(*translator).translateExprList(0xc0001a5678, 0xc0001046c0, 0x1, 0x1)
	/Users/gri/go/src/go/go2go/rewrite.go:852 +0x46
go/go2go.(*translator).translateStmt(0xc0001a5678, 0xc00011c7e0)
	/Users/gri/go/src/go/go2go/rewrite.go:583 +0x29d
go/go2go.(*translator).translateBlockStmt(0xc0001a5678, 0xc000106de0)
	/Users/gri/go/src/go/go2go/rewrite.go:544 +0x57
go/go2go.(*translator).translateFuncDecl(0xc0001a5678, 0xc00011d5b0)
	/Users/gri/go/src/go/go2go/rewrite.go:534 +0xc5
go/go2go.(*translator).translate(0xc0001a5678, 0xc000140280)
	/Users/gri/go/src/go/go2go/rewrite.go:461 +0x391
go/go2go.rewriteAST(0xc00012a240, 0xc000126360, 0x0, 0x0, 0xc000101770, 0xc000140280, 0x2583701, 0xc00012a5c0, 0x14197e0)
	/Users/gri/go/src/go/go2go/rewrite.go:257 +0xe5
go/go2go.rewriteFile(0xc00017a0a0, 0x43, 0xc00012a240, 0xc000126360, 0x0, 0x0, 0xc000101770, 0xc00017a230, 0x4c, 0xc000140280, ...)
	/Users/gri/go/src/go/go2go/rewrite.go:221 +0xb8
go/go2go.rewriteFilesInPath(0xc000126360, 0x0, 0x0, 0xc00017a0a0, 0x43, 0xc000104480, 0x1, 0x1, 0x0, 0x0, ...)
	/Users/gri/go/src/go/go2go/go2go.go:114 +0xc5c
go/go2go.rewriteToPkgs(0xc000126360, 0x0, 0x0, 0xc00017a0a0, 0x43, 0xc0001061a0, 0xc00017a0a0, 0x43, 0x7ffeefbffa96, 0x8)
	/Users/gri/go/src/go/go2go/go2go.go:46 +0x165
go/go2go.Rewrite(...)
	/Users/gri/go/src/go/go2go/go2go.go:30
main.translate(0xc000126360, 0xc00017a0a0, 0x43)
	/Users/gri/go/src/cmd/go2go/translate.go:15 +0x47
main.main()
	/Users/gri/go/src/cmd/go2go/main.go:54 +0xb25
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 30, 2020

Change https://golang.org/cl/240522 mentions this issue: [dev.go2go] go/go2go: instantiate embedded field when needed

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 30, 2020

Thanks, fixed on dev.go2go branch.

gopherbot pushed a commit that referenced this issue Jun 30, 2020
If an embedded field is an instantiated type, we need to instantiate
it when instantiating the whole type, in case the type arguments
themselves need instantiation.

Fixes #39953

Change-Id: I80b57456aa4f8e8b2eff82359066c37a9c2a40f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/240522
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.