| 1 | // These tests demonstrate the correct handling of symbols |
| 2 | // in packages other than two being compared. |
| 3 | // See the lines in establishCorrespondence beginning |
| 4 | // |
| 5 | // if newn, ok := new.(*types.Named); ok |
| 6 | package p |
| 7 | |
| 8 | // both |
| 9 | |
| 10 | // gofmt insists on grouping imports, so old and new |
| 11 | // must both have both imports. |
| 12 | import ( |
| 13 | "io" |
| 14 | "text/tabwriter" |
| 15 | ) |
| 16 | |
| 17 | // Here we have two named types in different packages. |
| 18 | // They have the same package-relative name, but we compare |
| 19 | // the package-qualified names. |
| 20 | |
| 21 | // old |
| 22 | var V io.Writer |
| 23 | var _ tabwriter.Writer |
| 24 | |
| 25 | // new |
| 26 | // i V: changed from io.Writer to text/tabwriter.Writer |
| 27 | var V tabwriter.Writer |
| 28 | var _ io.Writer |
| 29 | |
| 30 | // Here one type is a basic type. |
| 31 | // Example from https://go.dev/issue/61385. |
| 32 | // apidiff would previously report |
| 33 | // F2: changed from func(io.ReadCloser) to func(io.ReadCloser) |
| 34 | // io.ReadCloser: changed from interface{io.Reader; io.Closer} to int |
| 35 | |
| 36 | // old |
| 37 | func F1(io.ReadCloser) {} |
| 38 | |
| 39 | // new |
| 40 | // i F1: changed from func(io.ReadCloser) to func(int) |
| 41 | func F1(int) {} |
| 42 | |
| 43 | // both |
| 44 | func F2(io.ReadCloser) {} |