You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ staticcheck
main.go:6:2: this value of slice is never used (SA4006)
If I change the code to not provide the nil value explicitly, staticcheck passes. I believe this is a false positive because there's no value to use, and there's no reason to prefer one syntax over the other. In both cases the same value has been set on the variable and in both cases the nil value does not need to be more used than the other to be correct code.
package main
import "fmt"
func main() {
var slice []string
if true {
slice = []string{"1", "2"}
} else {
slice = []string{"3", "4"}
}
fmt.Println(slice)
}
staticcheck -version
staticcheck -debug.version
go version
go env
Staticcheck is detecting an explicit
nil
value given to a variable as a value that isn't used.See this simple example, that is a simpler version of the code I experienced this in:
If I change the code to not provide the
nil
value explicitly, staticcheck passes. I believe this is a false positive because there's no value to use, and there's no reason to prefer one syntax over the other. In both cases the same value has been set on the variable and in both cases the nil value does not need to be more used than the other to be correct code.The original error I experienced can be viewed in this CircleCI build and required this work-around to avoid the false positive.
The text was updated successfully, but these errors were encountered: