mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
[dev.typeparams] cmd/compile/internal/types2: interface identity must consider full type set
There is no (obvious) way to test this at the moment because we don't permit such constraint interfaces as ordinary types. Change-Id: Ieeec023ed82a2c71ed50d111f26916aba4a59099 Reviewed-on: https://go-review.googlesource.com/c/go/+/333889 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
2a8087817c
commit
dd8bdf4a1f
|
@ -270,12 +270,21 @@ func identical(x, y Type, cmpTags bool, p *ifacePair) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Interface:
|
case *Interface:
|
||||||
|
// Two interface types are identical if they describe the same type sets.
|
||||||
|
// With the existing implementation restriction, this simplifies to:
|
||||||
|
//
|
||||||
// Two interface types are identical if they have the same set of methods with
|
// Two interface types are identical if they have the same set of methods with
|
||||||
// the same names and identical function types. Lower-case method names from
|
// the same names and identical function types, and if any type restrictions
|
||||||
// different packages are always different. The order of the methods is irrelevant.
|
// are the same. Lower-case method names from different packages are always
|
||||||
|
// different. The order of the methods is irrelevant.
|
||||||
if y, ok := y.(*Interface); ok {
|
if y, ok := y.(*Interface); ok {
|
||||||
a := x.typeSet().methods
|
xset := x.typeSet()
|
||||||
b := y.typeSet().methods
|
yset := y.typeSet()
|
||||||
|
if !Identical(xset.types, yset.types) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
a := xset.methods
|
||||||
|
b := yset.methods
|
||||||
if len(a) == len(b) {
|
if len(a) == len(b) {
|
||||||
// Interface types are the only types where cycles can occur
|
// Interface types are the only types where cycles can occur
|
||||||
// that are not "terminated" via named types; and such cycles
|
// that are not "terminated" via named types; and such cycles
|
||||||
|
|
|
@ -362,16 +362,20 @@ func (u *unifier) nify(x, y Type, p *ifacePair) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Union:
|
case *Union:
|
||||||
// This should not happen with the current internal use of union types.
|
panic("unimplemented: unification with type sets described by types")
|
||||||
panic("type inference across union types not implemented")
|
|
||||||
|
|
||||||
case *Interface:
|
case *Interface:
|
||||||
// Two interface types are identical if they have the same set of methods with
|
// Two interface types are identical if they have the same set of methods with
|
||||||
// the same names and identical function types. Lower-case method names from
|
// the same names and identical function types. Lower-case method names from
|
||||||
// different packages are always different. The order of the methods is irrelevant.
|
// different packages are always different. The order of the methods is irrelevant.
|
||||||
if y, ok := y.(*Interface); ok {
|
if y, ok := y.(*Interface); ok {
|
||||||
a := x.typeSet().methods
|
xset := x.typeSet()
|
||||||
b := y.typeSet().methods
|
yset := y.typeSet()
|
||||||
|
if !Identical(xset.types, yset.types) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
a := xset.methods
|
||||||
|
b := yset.methods
|
||||||
if len(a) == len(b) {
|
if len(a) == len(b) {
|
||||||
// Interface types are the only types where cycles can occur
|
// Interface types are the only types where cycles can occur
|
||||||
// that are not "terminated" via named types; and such cycles
|
// that are not "terminated" via named types; and such cycles
|
||||||
|
|
Loading…
Reference in a new issue