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: embedded generic type panic: receiver type parameter inference failed #39758

Open
rogpeppe opened this issue Jun 22, 2020 · 6 comments
Open
Assignees
Milestone

Comments

@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Jun 22, 2020

commit 0a03088

The following program panics with "receiver type parameter inference failed".
It looks like it should be OK to me.

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

package main

import "fmt"

type F(type T) struct {}

func (f F(T)) Foo() {}

type G(type T) struct {
	(F(T))
}

func main() {
	var g G(int)
	g.Foo()
}

The full stack trace is:

panic: internal error: receiver type parameter inference failed [recovered]
	panic: internal error: receiver type parameter inference failed [recovered]
	panic: internal error: receiver type parameter inference failed

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc0000ba6c0, 0xc00010fbe0)
	/usr/local/go-faketime/src/go/types/check.go:251 +0x98
panic(0x642580, 0x6d2a40)
	/usr/local/go-faketime/src/runtime/panic.go:969 +0x175
go/types.(*Checker).stmt.func1(0xc0000ba6c0, 0xc0001394f0)
	/usr/local/go-faketime/src/go/types/stmt.go:304 +0x85
panic(0x642580, 0x6d2a40)
	/usr/local/go-faketime/src/runtime/panic.go:975 +0x3e9
go/types.(*Checker).selector(0xc0000ba6c0, 0xc0000b0b00, 0xc00009c4e0)
	/usr/local/go-faketime/src/go/types/call.go:534 +0x25b7
go/types.(*Checker).exprInternal(0xc0000ba6c0, 0xc0000b0b00, 0x6dada0, 0xc00009c4e0, 0x0, 0x0, 0x1c)
	/usr/local/go-faketime/src/go/types/expr.go:1308 +0x29cc
go/types.(*Checker).rawExpr(0xc0000ba6c0, 0xc0000b0b00, 0x6dada0, 0xc00009c4e0, 0x0, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/expr.go:1021 +0xc5
go/types.(*Checker).exprOrType(0xc0000ba6c0, 0xc0000b0b00, 0x6dada0, 0xc00009c4e0)
	/usr/local/go-faketime/src/go/types/expr.go:1705 +0x55
go/types.(*Checker).call(0xc0000ba6c0, 0xc0000b0b00, 0xc0000b0640, 0x0)
	/usr/local/go-faketime/src/go/types/call.go:17 +0x69
go/types.(*Checker).exprInternal(0xc0000ba6c0, 0xc0000b0b00, 0x6da620, 0xc0000b0640, 0x0, 0x0, 0x38)
	/usr/local/go-faketime/src/go/types/expr.go:1557 +0x1dd0
go/types.(*Checker).rawExpr(0xc0000ba6c0, 0xc0000b0b00, 0x6da620, 0xc0000b0640, 0x0, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/expr.go:1021 +0xc5
go/types.(*Checker).stmt(0xc0000ba6c0, 0x0, 0x6da8a0, 0xc000084620)
	/usr/local/go-faketime/src/go/types/stmt.go:330 +0x3e9b
go/types.(*Checker).stmtList(0xc0000ba6c0, 0x0, 0xc00009c500, 0x2, 0x2)
	/usr/local/go-faketime/src/go/types/stmt.go:125 +0xd1
go/types.(*Checker).funcBody(0xc0000ba6c0, 0xc00013a7e0, 0xc0000a63ec, 0x4, 0xc00013a960, 0xc000086d80, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/stmt.go:42 +0x257
go/types.(*Checker).funcDecl.func1()
	/usr/local/go-faketime/src/go/types/decl.go:786 +0x67
go/types.(*Checker).processDelayed(0xc0000ba6c0, 0x0)
	/usr/local/go-faketime/src/go/types/check.go:315 +0x3e
go/types.(*Checker).checkFiles(0xc0000ba6c0, 0xc000105cb8, 0x1, 0x1, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/check.go:283 +0x145
go/types.(*Checker).Files(...)
	/usr/local/go-faketime/src/go/types/check.go:256
go/types.(*Config).Check(0xc0000b0680, 0xc0000a63a0, 0x4, 0xc0000b0240, 0xc000105cb8, 0x1, 0x1, 0xc000081360, 0x0, 0x4b6d2f, ...)
	/usr/local/go-faketime/src/go/types/api.go:387 +0x188
go/go2go.RewriteBuffer(0xc0000813b0, 0x7fff21fd7dd8, 0x1e, 0xc0000f8000, 0x97, 0x297, 0x0, 0xc000086a20, 0xc0000869f0, 0xc0000869c0, ...)
	/usr/local/go-faketime/src/go/go2go/go2go.go:127 +0x24f
main.translateFile(0xc0000813b0, 0x7fff21fd7dd8, 0x1e)
	/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
main.main()
	/usr/local/go-faketime/src/cmd/go2go/main.go:64 +0x2ea
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 22, 2020

Thanks for the test case. This is a known internal bug at the moment. Probably won't get to this for a while (1-2 weeks) due to upcoming vacation.

@ajwerner
Copy link

@ajwerner ajwerner commented Jun 22, 2020

The below is a probably related but more confusing failure mode. https://go2goplay.golang.org/p/6S_TbYbI-Jo

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)
}

It panics with:

panic: -: unexpected type string character '₇' in "T₇"

goroutine 1 [running]:
go/go2go.(*translator).instantiatedName(0xc0001239b0, 0x0, 0xc00009d6c0, 0xc00009cf80, 0x2, 0x2, 0x2, 0xc00009d660, 0x2, 0x2)
	/usr/local/go-faketime/src/go/go2go/names.go:61 +0x72b
go/go2go.(*translator).lookupInstantiatedType(0xc0001239b0, 0xc0000b86c0, 0x0, 0x0, 0x0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:917 +0x409
go/go2go.(*translator).translateExpr(0xc0001239b0, 0xc00009c7e0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:596 +0x60b
go/go2go.(*translator).translateExpr(0xc0001239b0, 0xc0000b0800)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:576 +0x4ec
go/go2go.(*translator).translateExpr(0xc0001239b0, 0xc0000846a0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:619 +0x398
go/go2go.(*translator).translateExprList(0xc0001239b0, 0xc0000846a0, 0x1, 0x1)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:693 +0x46
go/go2go.(*translator).translateStmt(0xc0001239b0, 0xc00009c840)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:494 +0x29d
go/go2go.(*translator).translateBlockStmt(0xc0001239b0, 0xc000086db0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:455 +0x52
go/go2go.(*translator).translateFuncDecl(0xc0001239b0, 0xc00009d550)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:448 +0xc5
go/go2go.(*translator).translate(0xc0001239b0, 0xc0000c2280)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:376 +0x391
go/go2go.rewriteAST(0xc0000b0240, 0xc0000813b0, 0x0, 0x0, 0xc0000817c0, 0xc0000c2280, 0x1, 0xc000081360, 0xc0000817c0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:188 +0x109
go/go2go.RewriteBuffer(0xc0000813b0, 0x7fffbc08bdd8, 0x1e, 0xc0000fa000, 0x1e5, 0x3e5, 0x0, 0xc000086a20, 0xc0000869f0, 0xc0000869c0, ...)
	/usr/local/go-faketime/src/go/go2go/go2go.go:132 +0x2c5
main.translateFile(0xc0000813b0, 0x7fffbc08bdd8, 0x1e)
	/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
main.main()
	/usr/local/go-faketime/src/cmd/go2go/main.go:64 +0x2ea
@sebastien-rosset
Copy link

@sebastien-rosset sebastien-rosset commented Jun 25, 2020

Here is another program that exhibits a similar issue:
https://go2goplay.golang.org/p/q_pvY_wT1wj

panic: prog.go2:23:11: unexpected type string character '/' in "*math/big.Int"

goroutine 1 [running]:
go/go2go.(*translator).instantiatedName(0xc0000df9b0, 0x0, 0xc00000c9c0, 0xc00001d3a0, 0x1, 0x1, 0x1, 0x0, 0xc0000df201, 0x403518)
	/usr/local/go-faketime/src/go/go2go/names.go:61 +0x72b
go/go2go.(*translator).translateTypeInstantiation(0xc0000df9b0, 0xc000055830)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:784 +0x345
go/go2go.(*translator).translateExpr(0xc0000df9b0, 0xc000055830)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:616 +0x3bb
go/go2go.(*translator).translateValueSpec(0xc0000df9b0, 0xc00001c8e0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:428 +0x5b
go/go2go.(*translator).translateStmt(0xc0000df9b0, 0xc000084220)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:477 +0x10d
go/go2go.(*translator).translateBlockStmt(0xc0000df9b0, 0xc000010e10)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:455 +0x52
go/go2go.(*translator).translateFuncDecl(0xc0000df9b0, 0xc0000842c0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:448 +0xc5
go/go2go.(*translator).translate(0xc0000df9b0, 0xc000084300)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:376 +0x391
go/go2go.rewriteAST(0xc000072240, 0xc0000553b0, 0x0, 0x0, 0xc000055950, 0xc000084300, 0x1, 0xc000055360, 0xc000055950)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:188 +0x109
go/go2go.RewriteBuffer(0xc0000553b0, 0x7ffdd9200dd8, 0x1e, 0xc0000b8000, 0x281, 0x481, 0x0, 0xc000010a50, 0xc000010a20, 0xc0000109f0, ...)
	/usr/local/go-faketime/src/go/go2go/go2go.go:132 +0x2c5
main.translateFile(0xc0000553b0, 0x7ffdd9200dd8, 0x1e)
	/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
main.main()
	/usr/local/go-faketime/src/cmd/go2go/main.go:64 +0x2ea
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 25, 2020

@sebastien-rosset Thanks. That example works on the tip of the dev.go2go branch. The playground hasn't caught up yet.

@thepudds
Copy link

@thepudds thepudds commented Jul 4, 2020

Probably not super useful, but here is a shorter example (from #39634) that seems to trigger a similar crash as the report above from @rogpeppe :

package main
type C P
func (r C(P)) m() { y := C.m() }

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

In the current playground, that example and the example from @rogpeppe both panic in go/types.(*Checker).selector at src/go/types/call.go:534

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jul 7, 2020

This case is unrelated.

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
6 participants
You can’t perform that action at this time.