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: unification panic when type switching on uninstantiated type #40057

Closed
rogpeppe opened this issue Jul 5, 2020 · 4 comments
Closed

cmd/go2go: unification panic when type switching on uninstantiated type #40057

rogpeppe opened this issue Jul 5, 2020 · 4 comments
Assignees
Milestone

Comments

@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Jul 5, 2020

The following program panics when unifying instead of complaining about the type switch on the uninstantiated generic type.

package main

func main() {
	var x interface{}
	switch t := x.(type) {
	case *S:
		t.M()
	}
}

type S(type T) struct {}

func (i *S(T)) M() {
	panic("unreachable")
}

The panic traceback is:

panic: assertion failed [recovered]
	panic: assertion failed

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc00007c5a0, 0xc0000cbbe0)
	/usr/local/go-faketime/src/go/types/check.go:251 +0x98
panic(0x6498a0, 0x6db5e0)
	/usr/local/go-faketime/src/runtime/panic.go:969 +0x175
go/types.assert(...)
	/usr/local/go-faketime/src/go/types/errors.go:19
go/types.(*unifier).nify(0xc0000903c0, 0x6e6f20, 0xc00004a6c0, 0x6e6980, 0xc00007a240, 0x0, 0x6773e0)
	/usr/local/go-faketime/src/go/types/unify.go:351 +0x18c5
go/types.(*unifier).nify(0xc0000903c0, 0x6e6a20, 0xc00000c600, 0x6e6a20, 0xc00000c6c0, 0x0, 0x40f732)
	/usr/local/go-faketime/src/go/types/unify.go:233 +0xfca
go/types.(*unifier).unify(...)
	/usr/local/go-faketime/src/go/types/unify.go:38
go/types.(*Checker).infer(0xc00007c5a0, 0x80, 0xc00000e0e8, 0x1, 0x1, 0xc0000c8f78, 0xc0000c8f30, 0x1, 0x1, 0xc00001a470, ...)
	/usr/local/go-faketime/src/go/types/infer.go:52 +0x36a
go/types.(*Checker).selector(0xc00007c5a0, 0xc0000727c0, 0xc00000c300)
	/usr/local/go-faketime/src/go/types/call.go:529 +0xdfa
go/types.(*Checker).exprInternal(0xc00007c5a0, 0xc0000727c0, 0x6e3a20, 0xc00000c300, 0x0, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/expr.go:1320 +0x29cc
go/types.(*Checker).rawExpr(0xc00007c5a0, 0xc0000727c0, 0x6e3a20, 0xc00000c300, 0x0, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/expr.go:1033 +0xc5
go/types.(*Checker).exprOrType(0xc00007c5a0, 0xc0000727c0, 0x6e3a20, 0xc00000c300)
	/usr/local/go-faketime/src/go/types/expr.go:1717 +0x55
go/types.(*Checker).call(0xc00007c5a0, 0xc0000727c0, 0xc000072300, 0xc00007cea8)
	/usr/local/go-faketime/src/go/types/call.go:17 +0x69
go/types.(*Checker).exprInternal(0xc00007c5a0, 0xc0000727c0, 0x6e32a0, 0xc000072300, 0x0, 0x0, 0x38)
	/usr/local/go-faketime/src/go/types/expr.go:1569 +0x1dd0
go/types.(*Checker).rawExpr(0xc00007c5a0, 0xc0000727c0, 0x6e32a0, 0xc000072300, 0x0, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/expr.go:1033 +0xc5
go/types.(*Checker).stmt(0xc00007c5a0, 0x1, 0x6e3520, 0xc00001c5a0)
	/usr/local/go-faketime/src/go/types/stmt.go:330 +0x3e78
go/types.(*Checker).stmtList(0xc00007c5a0, 0x1, 0xc00001c5b0, 0x1, 0x1)
	/usr/local/go-faketime/src/go/types/stmt.go:125 +0xd1
go/types.(*Checker).stmt(0xc00007c5a0, 0x0, 0x6e3c20, 0xc000010c60)
	/usr/local/go-faketime/src/go/types/stmt.go:662 +0x1112
go/types.(*Checker).stmtList(0xc00007c5a0, 0x0, 0xc00000c320, 0x2, 0x2)
	/usr/local/go-faketime/src/go/types/stmt.go:125 +0xd1
go/types.(*Checker).funcBody(0xc00007c5a0, 0xc00004a4e0, 0xc00001a3e8, 0x4, 0xc00004a600, 0xc000010c90, 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:790 +0x67
go/types.(*Checker).processDelayed(0xc00007c5a0, 0x0)
	/usr/local/go-faketime/src/go/types/check.go:315 +0x3e
go/types.(*Checker).checkFiles(0xc00007c5a0, 0xc00003dcb8, 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(0xc000072540, 0xc00001a3e0, 0x4, 0xc000072240, 0xc00003dcb8, 0x1, 0x1, 0xc000055360, 0x0, 0x4b702f, ...)
	/usr/local/go-faketime/src/go/types/api.go:387 +0x188
go/go2go.RewriteBuffer(0xc00004a3c0, 0x7ffd420a9dec, 0x1e, 0xc0000ba000, 0xa6, 0x2a6, 0x0, 0xc000010a50, 0xc000010a20, 0xc0000109f0, ...)
	/usr/local/go-faketime/src/go/go2go/go2go.go:137 +0x24f
main.translateFile(0xc00004a3c0, 0x7ffd420a9dec, 0x1e)
	/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
main.main()
	/usr/local/go-faketime/src/cmd/go2go/main.go:65 +0x2f6
@thepudds
Copy link

@thepudds thepudds commented Jul 5, 2020

Possibly related to Crash 24 and/or Crash 25 in #39634 (comment).

In the current playground, all three of Crash 24, Crash 25, and @rogpeppe's example in this issue all crash in an assert in go/types.(*unifier).nify at go/types/unify.go:351.

However, the call stacks leading up to the failing assert are a bit different.

@rogpeppe's example:

... -> go/types.(*Checker).selector -> infer -> unify -> nify -> nify -> assert

Crash 24 & 25:

... -> go/types.(*Checker).selector -> infer -> unify -> nify -> assert

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 7, 2020

Change https://golang.org/cl/241126 mentions this issue: [dev.go2go] go/types: do not permit generic types in type switch type lists

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jul 7, 2020

Unrelated to crashes 24 or 25 of #39544.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jul 7, 2020

Fixed on dev.go2go.

@griesemer griesemer closed this Jul 7, 2020
gopherbot pushed a commit that referenced this issue Jul 7, 2020
… lists

Fixes #40057.

Change-Id: Ia1a99378614fda1d0cb3d6b9cf53bbf790fc2953
Reviewed-on: https://go-review.googlesource.com/c/go/+/241126
Reviewed-by: Robert Griesemer <gri@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
5 participants
You can’t perform that action at this time.