-
-
Notifications
You must be signed in to change notification settings - Fork 397
Open
Labels
Description
It seems like staticcheck is assuming that functions are always idempotent:
sfllaw@h2co3:~/src/staticcheck$ staticcheck main.go
main.go:14:39: identical expressions on the left and right side of the '==' operator (SA4000)given this main.go:
package main
import (
"fmt"
"math/rand/v2"
)
func f(n int) int {
return rand.IntN(n)
}
func main() {
fmt.Println("Function outputs:", f(10), f(10))
fmt.Println("are not always equal ", f(10) == f(10))
}Context
sfllaw@h2co3:~/src/staticcheck$ staticcheck -version
staticcheck 2025.1.1 (0.6.1)
sfllaw@h2co3:~/src/staticcheck$ staticcheck -debug.version
staticcheck 2025.1.1 (0.6.1)
Compiled with Go version: go1.23.2
Main module:
honnef.co/go/[email protected] (sum: h1:R094WgE8K4JirYjBaOpz/AvTyUu/3wbmAoskKN/pxTI=)
Dependencies:
github.com/BurntSushi/[email protected] (sum: h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=)
golang.org/x/exp/[email protected] (sum: h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=)
golang.org/x/[email protected] (sum: h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=)
golang.org/x/[email protected] (sum: h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=)
golang.org/x/[email protected] (sum: h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=)
sfllaw@h2co3:~/src/staticcheck$ go version
go version go1.23.2 linux/amd64