internal/apidiff: support materialized aliases

(The previous CL 559935 was insufficient.)

Also, improve test output.

Updates golang/go#65294

Change-Id: I05cafadce0dd6f18ff66d2ca462a3eb546c4ca81
Reviewed-on: https://go-review.googlesource.com/c/tools/+/577576
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Alan Donovan 2024-04-09 10:54:26 -04:00
Родитель 3520955d2d
Коммит b4b81864a1
4 изменённых файлов: 12 добавлений и 7 удалений

2
go.mod
Просмотреть файл

@ -10,6 +10,8 @@ require (
require golang.org/x/sync v0.7.0 require golang.org/x/sync v0.7.0
require github.com/google/go-cmp v0.6.0 // indirect
require ( require (
golang.org/x/sys v0.19.0 // indirect golang.org/x/sys v0.19.0 // indirect
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2

2
go.sum
Просмотреть файл

@ -1,3 +1,5 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=

Просмотреть файл

@ -208,7 +208,8 @@ 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 // Since these can change without affecting compatibility, we don't want users to
// be distracted by them, so we remove them. // be distracted by them, so we remove them.
func removeNamesFromSignature(t types.Type) types.Type { func removeNamesFromSignature(t types.Type) types.Type {
sig, ok := aliases.Unalias(t).(*types.Signature) t = aliases.Unalias(t)
sig, ok := t.(*types.Signature)
if !ok { if !ok {
return t return t
} }
@ -217,7 +218,7 @@ func removeNamesFromSignature(t types.Type) types.Type {
var vars []*types.Var var vars []*types.Var
for i := 0; i < p.Len(); i++ { for i := 0; i < p.Len(); i++ {
v := p.At(i) v := p.At(i)
vars = append(vars, types.NewVar(v.Pos(), v.Pkg(), "", v.Type())) vars = append(vars, types.NewVar(v.Pos(), v.Pkg(), "", aliases.Unalias(v.Type())))
} }
return types.NewTuple(vars...) return types.NewTuple(vars...)
} }

Просмотреть файл

@ -10,11 +10,11 @@ import (
"go/types" "go/types"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"sort" "sort"
"strings" "strings"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"golang.org/x/tools/go/packages" "golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/testenv" "golang.org/x/tools/internal/testenv"
) )
@ -42,12 +42,12 @@ func TestChanges(t *testing.T) {
report := Changes(oldpkg.Types, newpkg.Types) report := Changes(oldpkg.Types, newpkg.Types)
got := report.messages(false) got := report.messages(false)
if !reflect.DeepEqual(got, wanti) { if diff := cmp.Diff(wanti, got); diff != "" {
t.Errorf("incompatibles: got %v\nwant %v\n", got, wanti) t.Errorf("incompatibles (-want +got):\n%s", diff)
} }
got = report.messages(true) got = report.messages(true)
if !reflect.DeepEqual(got, wantc) { if diff := cmp.Diff(wantc, got); diff != "" {
t.Errorf("compatibles: got %v\nwant %v\n", got, wantc) t.Errorf("compatibles (-want +got):\n%s", diff)
} }
} }