@@ -7,13 +7,17 @@ func IncorrectSort() {
7
7
i := 5
8
8
sortFn := func (i , j int ) bool { return false }
9
9
sort .Slice (i , sortFn ) // want "sort.Slice's argument must be a slice; is called with int"
10
+ sort .SliceStable (i , sortFn ) // want "sort.SliceStable's argument must be a slice; is called with int"
11
+ sort .SliceIsSorted (i , sortFn ) // want "sort.SliceIsSorted's argument must be a slice; is called with int"
10
12
}
11
13
12
14
// CorrectSort sorts integers. It should not produce a diagnostic.
13
15
func CorrectSort () {
14
16
s := []int {2 , 3 , 5 , 6 }
15
17
sortFn := func (i , j int ) bool { return s [i ] < s [j ] }
16
18
sort .Slice (s , sortFn )
19
+ sort .SliceStable (s , sortFn )
20
+ sort .SliceIsSorted (s , sortFn )
17
21
}
18
22
19
23
// CorrectInterface sorts an interface with a slice
@@ -23,6 +27,8 @@ func CorrectInterface() {
23
27
s = interface {}([]int {2 , 1 , 0 })
24
28
sortFn := func (i , j int ) bool { return s .([]int )[i ] < s .([]int )[j ] }
25
29
sort .Slice (s , sortFn )
30
+ sort .SliceStable (s , sortFn )
31
+ sort .SliceIsSorted (s , sortFn )
26
32
}
27
33
28
34
type slicecompare interface {
@@ -41,6 +47,8 @@ func UnderlyingInterface() {
41
47
var s slicecompare
42
48
s = intslice ([]int {2 , 1 , 0 })
43
49
sort .Slice (s , s .compare )
50
+ sort .SliceStable (s , s .compare )
51
+ sort .SliceIsSorted (s , s .compare )
44
52
}
45
53
46
54
type mySlice []int
@@ -51,4 +59,6 @@ func UnderlyingSlice() {
51
59
s := mySlice {2 , 3 , 5 , 6 }
52
60
sortFn := func (i , j int ) bool { return s [i ] < s [j ] }
53
61
sort .Slice (s , sortFn )
62
+ sort .SliceStable (s , sortFn )
63
+ sort .SliceIsSorted (s , sortFn )
54
64
}
0 commit comments