-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
go/types should offer API for type unification, to allow clients to unify types that the type-checker hasn't already unified while type-checking code.
Staticcheck has a use for this as part of the unused check, to see if types implement possible instantiations of generic interfaces. For example, given
type Iface[T any] interface {
foo() []T
bar() T
}
type T1 struct{}
func (T1) foo() []int
func (T1) bar() int
type T2 struct{}
func (T2) foo() []int
func (T2) bar() string
we want to find out that T1 implements Iface[int] and that T2 doesn't implement any possible instantiation of Iface. For that, we would try to unify T1.foo and T1.bar with Iface.foo and Iface.bar, under a shared mapping of type parameters, and similarly do the same for T2.
As such, the API should allow unifying multiple pairs of types using the same mapping of type parameters to types, report success/failure, and allow querying the mapping.
/cc @findleyr
Metadata
Metadata
Assignees
Labels
Type
Projects
Status