Debian Codegraph @

gopls/internal/test/marker/testdata/quickfix/stub.txt

raw
1 This test checks the 'implement interface' quick fix.
2
3 -- go.mod --
4 module golang.org/lsptests/stub
5
6 go 1.18
7
8 -- other/other.go --
9 package other
10
11 import (
12 "bytes"
13 renamed_context "context"
14 )
15
16 type Interface interface {
17 Get(renamed_context.Context) *bytes.Buffer
18 }
19
20 -- add_selector.go --
21 package stub
22
23 import "io"
24
25 // This file tests that if an interface
26 // method references a type from its own package
27 // then our implementation must add the import/package selector
28 // in the concrete method if the concrete type is outside of the interface
29 // package
30 var _ io.ReaderFrom = &readerFrom{} //@quickfix("&readerFrom", re"cannot use", readerFrom)
31
32 type readerFrom struct{}
33 -- @readerFrom/add_selector.go --
34 @@ -13 +13,5 @@
35 +
36 +// ReadFrom implements [io.ReaderFrom].
37 +func (*readerFrom) ReadFrom(r io.Reader) (n int64, err error) {
38 + panic("unimplemented")
39 +}
40 -- assign.go --
41 package stub
42
43 import "io"
44
45 func _() {
46 var br io.ByteWriter
47 br = &byteWriter{} //@quickfix("&", re"does not implement", assign)
48 _ = br
49 }
50
51 type byteWriter struct{}
52 -- @assign/assign.go --
53 @@ -12 +12,5 @@
54 +
55 +// WriteByte implements [io.ByteWriter].
56 +func (b *byteWriter) WriteByte(c byte) error {
57 + panic("unimplemented")
58 +}
59 -- assign_multivars.go --
60 package stub
61
62 import "io"
63
64 func _() {
65 var br io.ByteWriter
66 var i int
67 i, br = 1, &multiByteWriter{} //@quickfix("&", re"does not implement", assign_multivars)
68 _, _ = i, br
69 }
70
71 type multiByteWriter struct{}
72 -- @assign_multivars/assign_multivars.go --
73 @@ -13 +13,5 @@
74 +
75 +// WriteByte implements [io.ByteWriter].
76 +func (m *multiByteWriter) WriteByte(c byte) error {
77 + panic("unimplemented")
78 +}
79 -- call_expr.go --
80 package stub
81
82 func main() {
83 check(&callExpr{}) //@quickfix("&", re"does not implement", call_expr)
84 }
85
86 func check(err error) {
87 if err != nil {
88 panic(err)
89 }
90 }
91
92 type callExpr struct{}
93 -- @call_expr/call_expr.go --
94 @@ -14 +14,5 @@
95 +
96 +// Error implements [error].
97 +func (c *callExpr) Error() string {
98 + panic("unimplemented")
99 +}
100 -- embedded.go --
101 package stub
102
103 import (
104 "io"
105 "sort"
106 )
107
108 var _ embeddedInterface = (*embeddedConcrete)(nil) //@quickfix("(", re"does not implement", embedded)
109
110 type embeddedConcrete struct{}
111
112 type embeddedInterface interface {
113 sort.Interface
114 io.Reader
115 }
116 -- @embedded/embedded.go --
117 @@ -12 +12,20 @@
118 +// Len implements [embeddedInterface].
119 +func (e *embeddedConcrete) Len() int {
120 + panic("unimplemented")
121 +}
122 +
123 +// Less implements [embeddedInterface].
124 +func (e *embeddedConcrete) Less(i int, j int) bool {
125 + panic("unimplemented")
126 +}
127 +
128 +// Read implements [embeddedInterface].
129 +func (e *embeddedConcrete) Read(p []byte) (n int, err error) {
130 + panic("unimplemented")
131 +}
132 +
133 +// Swap implements [embeddedInterface].
134 +func (e *embeddedConcrete) Swap(i int, j int) {
135 + panic("unimplemented")
136 +}
137 +
138 -- err.go --
139 package stub
140
141 func _() {
142 var br error = &customErr{} //@quickfix("&", re"does not implement", err)
143 _ = br
144 }
145
146 type customErr struct{}
147 -- @err/err.go --
148 @@ -9 +9,5 @@
149 +
150 +// Error implements [error].
151 +func (c *customErr) Error() string {
152 + panic("unimplemented")
153 +}
154 -- function_return.go --
155 package stub
156
157 import (
158 "io"
159 )
160
161 func newCloser() io.Closer {
162 return closer{} //@quickfix("c", re"does not implement", function_return)
163 }
164
165 type closer struct{}
166 -- @function_return/function_return.go --
167 @@ -12 +12,5 @@
168 +
169 +// Close implements [io.Closer].
170 +func (c closer) Close() error {
171 + panic("unimplemented")
172 +}
173 -- successive_function_return.go --
174 package stub
175
176 import (
177 "io"
178 )
179
180 func _() (a, b int, c io.Closer) {
181 return 1, 2, closer2{} //@quickfix("c", re"does not implement", successive)
182 }
183
184 type closer2 struct{}
185 -- @successive/successive_function_return.go --
186 @@ -12 +12,5 @@
187 +
188 +// Close implements [io.Closer].
189 +func (c closer2) Close() error {
190 + panic("unimplemented")
191 +}
192 -- generic_receiver.go --
193 package stub
194
195 import "io"
196
197 // This file tests that the stub method generator accounts for concrete
198 // types that have type parameters defined.
199 var _ io.ReaderFrom = &genReader[string, int]{} //@quickfix("&genReader", re"does not implement", generic_receiver)
200
201 type genReader[T, Y any] struct {
202 T T
203 Y Y
204 }
205 -- @generic_receiver/generic_receiver.go --
206 @@ -13 +13,5 @@
207 +
208 +// ReadFrom implements [io.ReaderFrom].
209 +func (g *genReader[T, Y]) ReadFrom(r io.Reader) (n int64, err error) {
210 + panic("unimplemented")
211 +}
212 -- ignored_imports.go --
213 package stub
214
215 import (
216 "compress/zlib"
217 . "io"
218 _ "io"
219 )
220
221 // This file tests that dot-imports and underscore imports
222 // are properly ignored and that a new import is added to
223 // reference method types
224
225 var (
226 _ Reader
227 _ zlib.Resetter = (*ignoredResetter)(nil) //@quickfix("(", re"does not implement", ignored_imports)
228 )
229
230 type ignoredResetter struct{}
231 -- @ignored_imports/ignored_imports.go --
232 @@ -19 +19,5 @@
233 +
234 +// Reset implements [zlib.Resetter].
235 +func (i *ignoredResetter) Reset(r Reader, dict []byte) error {
236 + panic("unimplemented")
237 +}
238 -- issue2606.go --
239 package stub
240
241 type I interface{ error }
242
243 type C int
244
245 var _ I = C(0) //@quickfix("C", re"does not implement", issue2606)
246 -- @issue2606/issue2606.go --
247 @@ -7 +7,5 @@
248 +// Error implements [I].
249 +func (c C) Error() string {
250 + panic("unimplemented")
251 +}
252 +
253 -- multi_var.go --
254 package stub
255
256 import "io"
257
258 // This test ensures that a variable declaration that
259 // has multiple values on the same line can still be
260 // analyzed correctly to target the interface implementation
261 // diagnostic.
262 var one, two, three io.Reader = nil, &multiVar{}, nil //@quickfix("&", re"does not implement", multi_var)
263
264 type multiVar struct{}
265 -- @multi_var/multi_var.go --
266 @@ -12 +12,5 @@
267 +
268 +// Read implements [io.Reader].
269 +func (m *multiVar) Read(p []byte) (n int, err error) {
270 + panic("unimplemented")
271 +}
272 -- pointer.go --
273 package stub
274
275 import "io"
276
277 func getReaderFrom() io.ReaderFrom {
278 return &pointerImpl{} //@quickfix("&", re"does not implement", pointer)
279 }
280
281 type pointerImpl struct{}
282 -- @pointer/pointer.go --
283 @@ -10 +10,5 @@
284 +
285 +// ReadFrom implements [io.ReaderFrom].
286 +func (p *pointerImpl) ReadFrom(r io.Reader) (n int64, err error) {
287 + panic("unimplemented")
288 +}
289 -- renamed_import.go --
290 package stub
291
292 import (
293 "compress/zlib"
294 myio "io"
295 )
296
297 var _ zlib.Resetter = &myIO{} //@quickfix("&", re"does not implement", renamed_import)
298 var _ myio.Reader
299
300 type myIO struct{}
301 -- @renamed_import/renamed_import.go --
302 @@ -12 +12,5 @@
303 +
304 +// Reset implements [zlib.Resetter].
305 +func (m *myIO) Reset(r myio.Reader, dict []byte) error {
306 + panic("unimplemented")
307 +}
308 -- renamed_import_iface.go --
309 package stub
310
311 import (
312 "golang.org/lsptests/stub/other"
313 )
314
315 // This file tests that if an interface
316 // method references an import from its own package
317 // that the concrete type does not yet import, and that import happens
318 // to be renamed, then we prefer the renaming of the interface.
319 var _ other.Interface = &otherInterfaceImpl{} //@quickfix("&otherInterfaceImpl", re"does not implement", renamed_import_iface)
320
321 type otherInterfaceImpl struct{}
322 -- @renamed_import_iface/renamed_import_iface.go --
323 @@ -4 +4,2 @@
324 + "bytes"
325 + "context"
326 @@ -14 +16,5 @@
327 +
328 +// Get implements [other.Interface].
329 +func (o *otherInterfaceImpl) Get(context.Context) *bytes.Buffer {
330 + panic("unimplemented")
331 +}
332 -- stdlib.go --
333 package stub
334
335 import (
336 "io"
337 )
338
339 var _ io.Writer = writer{} //@quickfix("w", re"does not implement", stdlib)
340
341 type writer struct{}
342 -- @stdlib/stdlib.go --
343 @@ -10 +10,5 @@
344 +
345 +// Write implements [io.Writer].
346 +func (w writer) Write(p []byte) (n int, err error) {
347 + panic("unimplemented")
348 +}