[dev.go2go] go/types: use the underlying type of type list entries

Type lists can contain defined types, make sure we use their
underlying types when computing operational types.

Change-Id: I8b6b11302f6b28977916e495f1486cc7b352e859
Reviewed-on: https://go-review.googlesource.com/c/go/+/239163
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Robert Griesemer 2020-06-19 21:42:22 -07:00
parent c0c872e8b0
commit 0a030888da
2 changed files with 15 additions and 2 deletions

View File

@ -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.

View File

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