Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

U1000 false positive if variable is used as part of initialization expression with side effects #1610

Open
hkeide opened this issue Oct 6, 2024 · 0 comments

Comments

@hkeide
Copy link

hkeide commented Oct 6, 2024

$ staticcheck -version
staticcheck 2024.1.1 (0.5.1)

$ staticcheck -debug.version
staticcheck 2024.1.1 (0.5.1)

Compiled with Go version: go1.23.0
Main module:
	honnef.co/go/tools@v0.5.1 (sum: h1:4bH5o3b5ZULQ4UrBmP+63W9r7qIkqJClEA9ko5YKx+I=)
Dependencies:
	github.com/BurntSushi/toml@v1.4.1-0.20240526193622-a339e1f7089c (sum: h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs=)
	golang.org/x/exp/typeparams@v0.0.0-20231108232855-2478ac86f678 (sum: h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ=)
	golang.org/x/mod@v0.17.0 (sum: h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=)
	golang.org/x/sync@v0.7.0 (sum: h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=)
	golang.org/x/tools@v0.21.1-0.20240531212143-b6235391adb3 (sum: h1:SHq4Rl+B7WvyM4XODon1LXtP7gcG49+7Jubt1gWWswY=)

$ go version
go version go1.23.0 darwin/arm64

$ staticcheck main.go
main.go:5:5: var integer is unused (U1000)
main.go:7:5: var ret is unused (U1000)
main.go:9:6: func f is unused (U1000)

$ go run main.go
[1]

main.go:

package main

import "fmt"

var integer = 1

var ret = f([]int{integer})

func f(slice []int) int {
	fmt.Println(slice)
	return 0
}

func main() {

}

Why it's wrong: the function f() is executed and has side effects, but its input and the function itself is marked as unused.

@hkeide hkeide added false-positive needs-triage Newly filed issue that needs triage labels Oct 6, 2024
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants