Go

Go

Made by DeepSource

Suspicious call to sort.Slice GO-W4009

Bug risk
Major

sort.Slice's parameter less (comparator) function should use the slice being sorted, and not some other slice.

Bad practice

package main

import (
    "sort"
)

func foo(x, y []int) {
    sort.Slice(x, (func i, j int) bool {
        return y[i] < y[j]
    })
}

Recommended

package main

import (
    "sort"
)

func foo(x, _ []int) {
    sort.Slice(x, (func i, j int) bool {
        return x[i] < x[j]
    })
}

References