Source file
test/fixedbugs/issue57184.go
1
2
3
4
5
6
7 package main
8
9 import (
10 "log"
11 "reflect"
12 "sort"
13 )
14
15 func main() {
16 const length = 257
17 x := make([]int64, length)
18 for i := 0; i < length; i++ {
19 x[i] = int64(i) * 27644437 % int64(length)
20 }
21
22 isLessStatic := func(i, j int) bool {
23 return x[i] < x[j]
24 }
25
26 isLessReflect := reflect.MakeFunc(reflect.TypeOf(isLessStatic), func(args []reflect.Value) []reflect.Value {
27 i := args[0].Int()
28 j := args[1].Int()
29 b := x[i] < x[j]
30 return []reflect.Value{reflect.ValueOf(b)}
31 }).Interface().(func(i, j int) bool)
32
33 sort.SliceStable(x, isLessReflect)
34
35 for i := 0; i < length-1; i++ {
36 if x[i] >= x[i+1] {
37 log.Fatalf("not sorted! (length=%v, idx=%v)\n%v\n", length, i, x)
38 }
39 }
40 }
41
View as plain text