| 1 |
package pkg |
| 2 |
|
| 3 |
import "context" |
| 4 |
|
| 5 |
type T string |
| 6 |
|
| 7 |
type T2 struct { |
| 8 |
A int |
| 9 |
} |
| 10 |
|
| 11 |
type T3 struct { |
| 12 |
A []int |
| 13 |
} |
| 14 |
|
| 15 |
func fn(arg1 interface{}, arg2 string) { |
| 16 |
var ctx context.Context |
| 17 |
context.WithValue(ctx, "hi", nil) //@ diag(`should not use built-in type string`) |
| 18 |
context.WithValue(ctx, arg1, nil) |
| 19 |
context.WithValue(ctx, arg2, nil) //@ diag(`should not use built-in type string`) |
| 20 |
v1 := interface{}("byte") |
| 21 |
context.WithValue(ctx, v1, nil) //@ diag(`should not use built-in type string`) |
| 22 |
|
| 23 |
var key T |
| 24 |
context.WithValue(ctx, key, nil) |
| 25 |
v2 := interface{}(key) |
| 26 |
context.WithValue(ctx, v2, nil) |
| 27 |
context.WithValue(ctx, T(""), nil) |
| 28 |
context.WithValue(ctx, string(key), nil) //@ diag(`should not use built-in type string`) |
| 29 |
|
| 30 |
context.WithValue(ctx, []byte(nil), nil) //@ diag(`must be comparable`) |
| 31 |
context.WithValue(ctx, T2{}, nil) |
| 32 |
context.WithValue(ctx, T3{}, nil) //@ diag(`must be comparable`) |
| 33 |
|
| 34 |
context.WithValue(ctx, struct{ key string }{"k"}, nil) |
| 35 |
var empty struct{} |
| 36 |
context.WithValue(ctx, struct{}{}, nil) //@ diag(`should not use empty anonymous struct`) |
| 37 |
context.WithValue(ctx, empty, nil) //@ diag(`should not use empty anonymous struct`) |
| 38 |
} |