@@ -36,7 +36,7 @@ func TestGenericBodies(t *testing.T) {
36
36
}
37
37
for _ , contents := range []string {
38
38
`
39
- package p
39
+ package p00
40
40
41
41
func f(x int) {
42
42
var i interface{}
@@ -46,22 +46,22 @@ func TestGenericBodies(t *testing.T) {
46
46
}
47
47
` ,
48
48
`
49
- package q
49
+ package p01
50
50
51
51
func f[T any](x T) {
52
52
print(x) //@ types(T)
53
53
}
54
54
` ,
55
55
`
56
- package r
56
+ package p02
57
57
58
58
func f[T ~int]() {
59
59
var x T
60
60
print(x) //@ types(T)
61
61
}
62
62
` ,
63
63
`
64
- package s
64
+ package p03
65
65
66
66
func a[T ~[4]byte](x T) {
67
67
for k, v := range x {
@@ -96,26 +96,26 @@ func TestGenericBodies(t *testing.T) {
96
96
97
97
func From() {
98
98
type A [4]byte
99
- print(a[A]) //@ types("func(x s .A)")
99
+ print(a[A]) //@ types("func(x p03 .A)")
100
100
101
101
type B *[4]byte
102
- print(b[B]) //@ types("func(x s .B)")
102
+ print(b[B]) //@ types("func(x p03 .B)")
103
103
104
104
type C []byte
105
- print(c[C]) //@ types("func(x s .C)")
105
+ print(c[C]) //@ types("func(x p03 .C)")
106
106
107
107
type D string
108
- print(d[D]) //@ types("func(x s .D)")
108
+ print(d[D]) //@ types("func(x p03 .D)")
109
109
110
110
type E map[int]string
111
- print(e[E]) //@ types("func(x s .E)")
111
+ print(e[E]) //@ types("func(x p03 .E)")
112
112
113
113
type F chan string
114
- print(f[F]) //@ types("func(x s .F)")
114
+ print(f[F]) //@ types("func(x p03 .F)")
115
115
}
116
116
` ,
117
117
`
118
- package t
118
+ package p05
119
119
120
120
func f[S any, T ~chan S](x T) {
121
121
for v := range x {
@@ -125,11 +125,11 @@ func TestGenericBodies(t *testing.T) {
125
125
126
126
func From() {
127
127
type F chan string
128
- print(f[string, F]) //@ types("func(x t .F)")
128
+ print(f[string, F]) //@ types("func(x p05 .F)")
129
129
}
130
130
` ,
131
131
`
132
- package u
132
+ package p06
133
133
134
134
func fibonacci[T ~chan int](c, quit T) {
135
135
x, y := 0, 1
@@ -155,24 +155,24 @@ func TestGenericBodies(t *testing.T) {
155
155
type F chan int
156
156
c := make(F)
157
157
quit := make(F)
158
- print(start[F], c, quit) //@ types("func(c u .F, quit u .F)", "u .F", "u .F")
159
- print(fibonacci[F], c, quit) //@ types("func(c u .F, quit u .F)", "u .F", "u .F")
158
+ print(start[F], c, quit) //@ types("func(c p06 .F, quit p06 .F)", "p06 .F", "p06 .F")
159
+ print(fibonacci[F], c, quit) //@ types("func(c p06 .F, quit p06 .F)", "p06 .F", "p06 .F")
160
160
}
161
161
` ,
162
162
`
163
- package v
163
+ package p07
164
164
165
165
func f[T ~struct{ x int; y string }](i int) T {
166
166
u := []T{ T{0, "lorem"}, T{1, "ipsum"}}
167
167
return u[i]
168
168
}
169
169
func From() {
170
170
type S struct{ x int; y string }
171
- print(f[S]) //@ types("func(i int) v .S")
171
+ print(f[S]) //@ types("func(i int) p07 .S")
172
172
}
173
173
` ,
174
174
`
175
- package w
175
+ package p08
176
176
177
177
func f[T ~[4]int8](x T, l, h int) []int8 {
178
178
return x[l:h]
@@ -189,11 +189,11 @@ func TestGenericBodies(t *testing.T) {
189
189
type H []int32
190
190
print(f[F](F{}, 0, 0)) //@ types("[]int8")
191
191
print(g[G](nil, 0, 0)) //@ types("[]int16")
192
- print(h[H](nil, 0, 0)) //@ types("w .H")
192
+ print(h[H](nil, 0, 0)) //@ types("p08 .H")
193
193
}
194
194
` ,
195
195
`
196
- package x
196
+ package p09
197
197
198
198
func h[E any, T ~[]E](x T, l, h int) []E {
199
199
s := x[l:h]
@@ -206,7 +206,7 @@ func TestGenericBodies(t *testing.T) {
206
206
}
207
207
` ,
208
208
`
209
- package y
209
+ package p10
210
210
211
211
// Test "make" builtin with different forms on core types and
212
212
// when capacities are constants or variable.
@@ -236,7 +236,7 @@ func TestGenericBodies(t *testing.T) {
236
236
}
237
237
` ,
238
238
`
239
- package z
239
+ package p11
240
240
241
241
func h[T ~[4]int](x T) {
242
242
print(len(x), cap(x)) //@ types(int, int)
@@ -253,7 +253,7 @@ func TestGenericBodies(t *testing.T) {
253
253
}
254
254
` ,
255
255
`
256
- package a
256
+ package p12
257
257
258
258
func f[E any, F ~func() E](x F) {
259
259
print(x, x()) //@ types(F, E)
@@ -265,7 +265,7 @@ func TestGenericBodies(t *testing.T) {
265
265
}
266
266
` ,
267
267
`
268
- package b
268
+ package p13
269
269
270
270
func f[E any, M ~map[string]E](m M) {
271
271
y, ok := m["lorem"]
@@ -277,7 +277,7 @@ func TestGenericBodies(t *testing.T) {
277
277
}
278
278
` ,
279
279
`
280
- package c
280
+ package p14
281
281
282
282
func a[T interface{ []int64 | [5]int64 }](x T) int64 {
283
283
print(x, x[2], x[3]) //@ types(T, int64, int64)
@@ -318,25 +318,25 @@ func TestGenericBodies(t *testing.T) {
318
318
}
319
319
` ,
320
320
`
321
- package d
321
+ package p15
322
322
323
323
type MyInt int
324
324
type Other int
325
325
type MyInterface interface{ foo() }
326
326
327
327
// ChangeType tests
328
- func ct0(x int) { v := MyInt(x); print(x, v) /*@ types(int, "d .MyInt")*/ }
328
+ func ct0(x int) { v := MyInt(x); print(x, v) /*@ types(int, "p15 .MyInt")*/ }
329
329
func ct1[T MyInt | Other, S int ](x S) { v := T(x); print(x, v) /*@ types(S, T)*/ }
330
330
func ct2[T int, S MyInt | int ](x S) { v := T(x); print(x, v) /*@ types(S, T)*/ }
331
331
func ct3[T MyInt | Other, S MyInt | int ](x S) { v := T(x) ; print(x, v) /*@ types(S, T)*/ }
332
332
333
333
// Convert tests
334
- func co0[T int | int8](x MyInt) { v := T(x); print(x, v) /*@ types("d .MyInt", T)*/}
335
- func co1[T int | int8](x T) { v := MyInt(x); print(x, v) /*@ types(T, "d .MyInt")*/ }
334
+ func co0[T int | int8](x MyInt) { v := T(x); print(x, v) /*@ types("p15 .MyInt", T)*/}
335
+ func co1[T int | int8](x T) { v := MyInt(x); print(x, v) /*@ types(T, "p15 .MyInt")*/ }
336
336
func co2[S, T int | int8](x T) { v := S(x); print(x, v) /*@ types(T, S)*/ }
337
337
338
338
// MakeInterface tests
339
- func mi0[T MyInterface](x T) { v := MyInterface(x); print(x, v) /*@ types(T, "d .MyInterface")*/ }
339
+ func mi0[T MyInterface](x T) { v := MyInterface(x); print(x, v) /*@ types(T, "p15 .MyInterface")*/ }
340
340
341
341
// NewConst tests
342
342
func nc0[T any]() { v := (*T)(nil); print(v) /*@ types("*T")*/}
@@ -346,43 +346,51 @@ func TestGenericBodies(t *testing.T) {
346
346
func sl1[T *[4]int | *[2]int, S []int](x S) { v := T(x); print(x, v) /*@ types(S, T)*/ }
347
347
` ,
348
348
`
349
- package e
349
+ package p16
350
350
351
351
func c[T interface{ foo() string }](x T) {
352
352
print(x, x.foo, x.foo()) /*@ types(T, "func() string", string)*/
353
353
}
354
354
` ,
355
- `package f
355
+ `
356
+ package p17
356
357
357
358
func eq[T comparable](t T, i interface{}) bool {
358
359
return t == i
359
360
}
360
361
` ,
361
362
// TODO(59983): investigate why writing g.c panics in (*FieldAddr).String.
362
- `package g
363
+ `
364
+ package p18
365
+
363
366
type S struct{ f int }
364
367
func c[P *S]() []P { return []P{{f: 1}} }
365
368
` ,
366
- `package h
369
+ `
370
+ package p19
371
+
367
372
func sign[bytes []byte | string](s bytes) (bool, bool) {
368
373
neg := false
369
374
if len(s) > 0 && (s[0] == '-' || s[0] == '+') {
370
375
neg = s[0] == '-'
371
376
s = s[1:]
372
377
}
373
378
return !neg, len(s) > 0
374
- }` ,
375
- `package i
379
+ }
380
+ ` ,
381
+ `package p20
382
+
376
383
func digits[bytes []byte | string](s bytes) bool {
377
384
for _, c := range []byte(s) {
378
385
if c < '0' || '9' < c {
379
386
return false
380
387
}
381
388
}
382
389
return true
383
- }` ,
390
+ }
391
+ ` ,
384
392
`
385
- package j
393
+ package p21
386
394
387
395
type E interface{}
388
396
@@ -394,7 +402,7 @@ func TestGenericBodies(t *testing.T) {
394
402
}
395
403
` ,
396
404
`
397
- package k
405
+ package p22
398
406
399
407
func f[M any, PM *M](p PM) {
400
408
var m M
@@ -404,7 +412,7 @@ func TestGenericBodies(t *testing.T) {
404
412
}
405
413
` ,
406
414
`
407
- package l
415
+ package p23
408
416
409
417
type A struct{int}
410
418
func (*A) Marker() {}
@@ -422,10 +430,11 @@ func TestGenericBodies(t *testing.T) {
422
430
Marker()
423
431
}](v T) {
424
432
v.Marker()
425
- a := *(any(v).(*A)); print(a) /*@ types("l.A")*/
426
- b := *(any(v).(*B)); print(b) /*@ types("l.B")*/
427
- c := *(any(v).(*C)); print(c) /*@ types("l.C")*/
428
- }` ,
433
+ a := *(any(v).(*A)); print(a) /*@ types("p23.A")*/
434
+ b := *(any(v).(*B)); print(b) /*@ types("p23.B")*/
435
+ c := *(any(v).(*C)); print(c) /*@ types("p23.C")*/
436
+ }
437
+ ` ,
429
438
} {
430
439
contents := contents
431
440
pkgname := packageName (t , contents )
0 commit comments