github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/staticcheck/sa1029/testdata/src/example.com/CheckWithValueKey/CheckWithValueKey.go (about)

     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  }