Skip to content

Commit b4b8186

Browse files
committed
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 <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 3520955 commit b4b8186

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ require (
1010

1111
require golang.org/x/sync v0.7.0
1212

13+
require github.com/google/go-cmp v0.6.0 // indirect
14+
1315
require (
1416
golang.org/x/sys v0.19.0 // indirect
1517
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2

go.sum

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

internal/apidiff/apidiff.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ func (d *differ) typeChanged(obj types.Object, part string, old, new types.Type)
208208
// Since these can change without affecting compatibility, we don't want users to
209209
// be distracted by them, so we remove them.
210210
func removeNamesFromSignature(t types.Type) types.Type {
211-
sig, ok := aliases.Unalias(t).(*types.Signature)
211+
t = aliases.Unalias(t)
212+
sig, ok := t.(*types.Signature)
212213
if !ok {
213214
return t
214215
}
@@ -217,7 +218,7 @@ func removeNamesFromSignature(t types.Type) types.Type {
217218
var vars []*types.Var
218219
for i := 0; i < p.Len(); i++ {
219220
v := p.At(i)
220-
vars = append(vars, types.NewVar(v.Pos(), v.Pkg(), "", v.Type()))
221+
vars = append(vars, types.NewVar(v.Pos(), v.Pkg(), "", aliases.Unalias(v.Type())))
221222
}
222223
return types.NewTuple(vars...)
223224
}

internal/apidiff/apidiff_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"go/types"
1111
"os"
1212
"path/filepath"
13-
"reflect"
1413
"sort"
1514
"strings"
1615
"testing"
1716

17+
"github.com/google/go-cmp/cmp"
1818
"golang.org/x/tools/go/packages"
1919
"golang.org/x/tools/internal/testenv"
2020
)
@@ -42,12 +42,12 @@ func TestChanges(t *testing.T) {
4242
report := Changes(oldpkg.Types, newpkg.Types)
4343

4444
got := report.messages(false)
45-
if !reflect.DeepEqual(got, wanti) {
46-
t.Errorf("incompatibles: got %v\nwant %v\n", got, wanti)
45+
if diff := cmp.Diff(wanti, got); diff != "" {
46+
t.Errorf("incompatibles (-want +got):\n%s", diff)
4747
}
4848
got = report.messages(true)
49-
if !reflect.DeepEqual(got, wantc) {
50-
t.Errorf("compatibles: got %v\nwant %v\n", got, wantc)
49+
if diff := cmp.Diff(wantc, got); diff != "" {
50+
t.Errorf("compatibles (-want +got):\n%s", diff)
5151
}
5252
}
5353

0 commit comments

Comments
 (0)