diff --git a/src/go/types/testdata/typeinst2.go2 b/src/go/types/testdata/typeinst2.go2 index 6ff9b6510a..204a18cdc4 100644 --- a/src/go/types/testdata/typeinst2.go2 +++ b/src/go/types/testdata/typeinst2.go2 @@ -172,6 +172,18 @@ type _ interface { type struct{f int}, struct{g int}, struct /* ERROR duplicate type */ {f int} } +// Interface type lists can contain any type, incl. *Named types. +// Verify that we use the underlying type to compute the operational type. +type MyInt int +func add1(type T interface{type MyInt})(x T) T { + return x + 1 +} + +type MyString string +func double(type T interface{type MyInt, MyString})(x T) T { + return x + x +} + // Embedding of interfaces with type lists leads to interfaces // with type lists that are the intersection of the embedded // type lists. diff --git a/src/go/types/type.go b/src/go/types/type.go index fd1777b327..370a296c7f 100644 --- a/src/go/types/type.go +++ b/src/go/types/type.go @@ -828,7 +828,8 @@ func optype(typ Type) Type { // (type T interface { type T }). // See also issue #39680. if u := t.Bound().allTypes; u != nil && u != typ { - return u + // u != typ and u is a type parameter => u.Under() != typ, so this is ok + return u.Under() } return theTop } @@ -979,7 +980,7 @@ func (t *Struct) Under() Type { return t } func (t *Pointer) Under() Type { return t } func (t *Tuple) Under() Type { return t } func (t *Signature) Under() Type { return t } -func (t *Sum) Under() Type { return t } +func (t *Sum) Under() Type { return t } // TODO(gri) is this correct? func (t *Interface) Under() Type { return t } func (t *Map) Under() Type { return t } func (t *Chan) Under() Type { return t }