Skip to content

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

Closed
@rogpeppe

Description

@rogpeppe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions