github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/staticcheck/sa1028/testdata/src/example.com/CheckSortSlice/slice.go (about) 1 package pkg 2 3 import "sort" 4 5 type T1 []int 6 type T2 T1 7 type T3 [1]int 8 type T4 string 9 10 func fn(arg1 interface{}, arg2 []int) { 11 var v1 T1 12 var v2 T2 13 var v3 T3 14 var v4 T4 15 var v5 []int 16 var v6 interface{} = []int{} 17 var v7 interface{} 18 if true { 19 v7 = []int{} 20 } else { 21 v7 = 0 22 } 23 var v8 interface{} = 0 24 sort.Slice(arg1, nil) 25 sort.Slice(arg2, nil) 26 sort.Slice(v1, nil) 27 sort.Slice(v2, nil) 28 sort.Slice(v3, nil) //@ diag(`sort.Slice must only be called on slices, was called on [1]int`) 29 sort.Slice(v4, nil) //@ diag(`sort.Slice must only be called on slices, was called on string`) 30 sort.Slice(v5, nil) 31 sort.Slice(v6, nil) 32 sort.Slice(v7, nil) 33 sort.Slice(v8, nil) //@ diag(`sort.Slice must only be called on slices, was called on int`) 34 sort.Slice([]int{}, nil) 35 sort.Slice(0, nil) //@ diag(`sort.Slice must only be called on slices, was called on int`) 36 sort.Slice(nil, nil) //@ diag(`cannot call sort.Slice on nil literal`) 37 sort.SliceIsSorted(0, nil) //@ diag(`sort.SliceIsSorted must only be called on slices, was called on int`) 38 sort.SliceStable(0, nil) //@ diag(`sort.SliceStable must only be called on slices, was called on int`) 39 }