diff --git a/internal/apidiff/apidiff.go b/internal/apidiff/apidiff.go index 873ee85fb..087e112e5 100644 --- a/internal/apidiff/apidiff.go +++ b/internal/apidiff/apidiff.go @@ -19,6 +19,8 @@ import ( "go/constant" "go/token" "go/types" + + "golang.org/x/tools/internal/aliases" ) // Changes reports on the differences between the APIs of the old and new packages. @@ -206,7 +208,7 @@ func (d *differ) typeChanged(obj types.Object, part string, old, new types.Type) // Since these can change without affecting compatibility, we don't want users to // be distracted by them, so we remove them. func removeNamesFromSignature(t types.Type) types.Type { - sig, ok := t.(*types.Signature) + sig, ok := aliases.Unalias(t).(*types.Signature) if !ok { return t } diff --git a/internal/apidiff/compatibility.go b/internal/apidiff/compatibility.go index 2e327485b..0d2d2b345 100644 --- a/internal/apidiff/compatibility.go +++ b/internal/apidiff/compatibility.go @@ -8,9 +8,13 @@ import ( "fmt" "go/types" "reflect" + + "golang.org/x/tools/internal/aliases" ) func (d *differ) checkCompatible(otn *types.TypeName, old, new types.Type) { + old = aliases.Unalias(old) + new = aliases.Unalias(new) switch old := old.(type) { case *types.Interface: if new, ok := new.(*types.Interface); ok { @@ -268,7 +272,7 @@ func (d *differ) checkCompatibleDefined(otn *types.TypeName, old *types.Named, n return } // Interface method sets are checked in checkCompatibleInterface. - if _, ok := old.Underlying().(*types.Interface); ok { + if types.IsInterface(old) { return } @@ -287,7 +291,7 @@ func (d *differ) checkMethodSet(otn *types.TypeName, oldt, newt types.Type, addc oldMethodSet := exportedMethods(oldt) newMethodSet := exportedMethods(newt) msname := otn.Name() - if _, ok := oldt.(*types.Pointer); ok { + if _, ok := aliases.Unalias(oldt).(*types.Pointer); ok { msname = "*" + msname } for name, oldMethod := range oldMethodSet { @@ -349,9 +353,9 @@ func receiverType(method types.Object) types.Type { } func receiverNamedType(method types.Object) *types.Named { - switch t := receiverType(method).(type) { + switch t := aliases.Unalias(receiverType(method)).(type) { case *types.Pointer: - return t.Elem().(*types.Named) + return aliases.Unalias(t.Elem()).(*types.Named) case *types.Named: return t default: @@ -360,6 +364,6 @@ func receiverNamedType(method types.Object) *types.Named { } func hasPointerReceiver(method types.Object) bool { - _, ok := receiverType(method).(*types.Pointer) + _, ok := aliases.Unalias(receiverType(method)).(*types.Pointer) return ok } diff --git a/internal/apidiff/correspondence.go b/internal/apidiff/correspondence.go index 0d7b4c5a5..dd2f51781 100644 --- a/internal/apidiff/correspondence.go +++ b/internal/apidiff/correspondence.go @@ -7,6 +7,8 @@ package apidiff import ( "go/types" "sort" + + "golang.org/x/tools/internal/aliases" ) // Two types are correspond if they are identical except for defined types, @@ -31,6 +33,8 @@ func (d *differ) correspond(old, new types.Type) bool { // Compare this to the implementation of go/types.Identical. func (d *differ) corr(old, new types.Type, p *ifacePair) bool { // Structure copied from types.Identical. + old = aliases.Unalias(old) + new = aliases.Unalias(new) switch old := old.(type) { case *types.Basic: return types.Identical(old, new)