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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@griesemer
Copy link
Contributor

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
@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 30, 2020
@griesemer griesemer added this to the Unreleased milestone Jun 30, 2020
@gopherbot
Copy link

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

@ianlancetaylor
Copy link
Contributor

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>
@golang golang locked and limited conversation to collaborators Jun 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

3 participants