unused: deduplicate empty interface
@@ -6,7 +6,7 @@ import (
// Identical reports whether x and y are identical types.
// Unlike types.Identical, receivers of Signature types are not ignored.
-// Unlike types.Identical, interfaces are compared via pointer equality.
+// Unlike types.Identical, interfaces are compared via pointer equality (except for the empty interface, which gets deduplicated).
// Unlike types.Identical, structs are compared via pointer equality.
func Identical(x, y types.Type) (ret bool) {
if !types.Identical(x, y) {
@@ -48,6 +48,13 @@ func Identical(x, y types.Type) (ret bool) {
// should be impossible
return true
}
+ if x.NumEmbeddeds() == 0 &&
+ y.NumEmbeddeds() == 0 &&
+ x.NumMethods() == 0 &&
+ y.NumMethods() == 0 {
+ // all truly empty interfaces are the same
+ return true
+ }
return x == y
case *types.Signature:
y, ok := y.(*types.Signature)
