Debian Codegraph @

apidiff/testdata/types.go

raw symbols SCIP
1 package p
2
3 // both
4 import "io"
5
6 // old
7 type u1 int
8
9 // both
10 type u2 int
11
12 // old
13 const C5 = 3
14
15 type (
16 A1 [1]int
17 A2 [2]int
18 A3 [C5]int
19 )
20
21 // new
22 // i C5: value changed from 3 to 4
23 const C5 = 4
24
25 type (
26 A1 [1]int
27 // i A2: changed from [2]int to [2]bool
28 A2 [2]bool
29 // i A3: changed from [3]int to [4]int
30 A3 [C5]int
31 )
32
33 // old
34 type (
35 Sl []int
36 P1 *int
37 P2 *u1
38 )
39
40 // new
41 type (
42 // i Sl: changed from []int to []string
43 Sl []string
44 // i P1: changed from *int to **bool
45 P1 **bool
46 P2 *u2 // OK: u1 corresponds to u2
47 )
48
49 // old
50 type Bc1 int32
51 type Bc2 uint
52 type Bc3 float32
53 type Bc4 complex64
54
55 // new
56 // c Bc1: changed from int32 to int
57 type Bc1 int
58
59 // c Bc2: changed from uint to uint64
60 type Bc2 uint64
61
62 // c Bc3: changed from float32 to float64
63 type Bc3 float64
64
65 // c Bc4: changed from complex64 to complex128
66 type Bc4 complex128
67
68 // old
69 type Bi1 int32
70 type Bi2 uint
71 type Bi3 float64
72 type Bi4 complex128
73
74 // new
75 // i Bi1: changed from int32 to int16
76 type Bi1 int16
77
78 // i Bi2: changed from uint to uint32
79 type Bi2 uint32
80
81 // i Bi3: changed from float64 to float32
82 type Bi3 float32
83
84 // i Bi4: changed from complex128 to complex64
85 type Bi4 complex64
86
87 // old
88 type (
89 M1 map[string]int
90 M2 map[string]int
91 M3 map[string]int
92 )
93
94 // new
95 type (
96 M1 map[string]int
97 // i M2: changed from map[string]int to map[int]int
98 M2 map[int]int
99 // i M3: changed from map[string]int to map[string]string
100 M3 map[string]string
101 )
102
103 // old
104 type (
105 Ch1 chan int
106 Ch2 <-chan int
107 Ch3 chan int
108 Ch4 <-chan int
109 )
110
111 // new
112 type (
113 // i Ch1, element type: changed from int to bool
114 Ch1 chan bool
115 // i Ch2: changed direction
116 Ch2 chan<- int
117 // i Ch3: changed direction
118 Ch3 <-chan int
119 // c Ch4: removed direction
120 Ch4 chan int
121 )
122
123 // old
124 type I1 interface {
125 M1()
126 M2()
127 }
128
129 // new
130 type I1 interface {
131 // M1()
132 // i I1.M1: removed
133 M2(int)
134 // i I1.M2: changed from func() to func(int)
135 M3()
136 // i I1.M3: added
137 m()
138 // i I1.m: added unexported method
139 }
140
141 // old
142 type I2 interface {
143 M1()
144 m()
145 }
146
147 // new
148 type I2 interface {
149 M1()
150 // m() Removing an unexported method is OK.
151 m2() // OK, because old already had an unexported method
152 // c I2.M2: added
153 M2()
154 }
155
156 // old
157 type I3 interface {
158 io.Reader
159 M()
160 }
161
162 // new
163 // OK: what matters is the method set; the name of the embedded
164 // interface isn't important.
165 type I3 interface {
166 M()
167 Read([]byte) (int, error)
168 }
169
170 // old
171 type I4 io.Writer
172
173 // new
174 // OK: in both, I4 is a distinct type from io.Writer, and
175 // the old and new I4s have the same method set.
176 type I4 interface {
177 Write([]byte) (int, error)
178 }
179
180 // old
181 type I5 = io.Writer
182
183 // new
184 // i I5: changed from io.Writer to I5
185 // In old, I5 and io.Writer are the same type; in new,
186 // they are different. That can break something like:
187 //
188 // var _ func(io.Writer) = func(pkg.I6) {}
189 type I5 io.Writer
190
191 // old
192 type I6 interface{ Write([]byte) (int, error) }
193
194 // new
195 // i I6: changed from I6 to io.Writer
196 // Similar to the above.
197 type I6 = io.Writer
198
199 //// correspondence with a basic type
200 // Basic types are technically defined types, but they aren't
201 // represented that way in go/types, so the cases below are special.
202
203 // both
204 type T1 int
205
206 // old
207 var VT1 T1
208
209 // new
210 // i VT1: changed from T1 to int
211 // This fails because old T1 corresponds to both int and new T1.
212 var VT1 int
213
214 // old
215 type t2 int
216
217 var VT2 t2
218
219 // new
220 // OK: t2 corresponds to int. It's fine that old t2
221 // doesn't exist in new.
222 var VT2 int
223
224 // both
225 type t3 int
226
227 func (t3) M() {}
228
229 // old
230 var VT3 t3
231
232 // new
233 // i t3.M: removed
234 // Here the change from t3 to int is incompatible
235 // because old t3 has an exported method.
236 var VT3 int
237
238 // old
239 var VT4 int
240
241 // new
242 type t4 int
243
244 // i VT4: changed from int to t4
245 // This is incompatible because of code like
246 //
247 // VT4 + int(1)
248 //
249 // which works in old but fails in new.
250 // The difference from the above cases is that
251 // in those, we were merging two types into one;
252 // here, we are splitting int into t4 and int.
253 var VT4 t4