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

staticcheck: flag recursive closure that never gets used #1511

Open
seiyab opened this issue Mar 29, 2024 · 1 comment
Open

staticcheck: flag recursive closure that never gets used #1511

seiyab opened this issue Mar 29, 2024 · 1 comment

Comments

@seiyab
Copy link

seiyab commented Mar 29, 2024

  • The output of 'staticcheck -version'
staticcheck 2023.1.7 (v0.4.7)
  • The output of 'staticcheck -debug.version' (it is fine if this command fails)
staticcheck 2023.1.7 (v0.4.7)

Compiled with Go version: go1.21.1
Main module:
        honnef.co/go/tools@v0.4.7 (sum: h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=)
Dependencies:
        github.com/BurntSushi/toml@v1.2.1 (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
        golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
        golang.org/x/mod@v0.12.0 (sum: h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=)
        golang.org/x/sys@v0.11.0 (sum: h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=)
        golang.org/x/tools@v0.12.1-0.20230825192346-2191a27a6dc5 (sum: h1:Vk4mysSz+GqQK2eqgWbo4zEO89wkeAjJiFIr9bpqa8k=)
  • The output of 'go version'
go version go1.21.1 darwin/arm64
  • The output of 'go env'
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/seiya/Library/Caches/go-build'
GOENV='/Users/seiya/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/seiya/.asdf/installs/golang/1.21.1/packages/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/seiya/.asdf/installs/golang/1.21.1/packages'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/seiya/.asdf/installs/golang/1.21.1/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/seiya/.asdf/installs/golang/1.21.1/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/seiya/Projects/repro/staticcheck-fixture/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/wb/yt882gm52pzdsz3_vcvbp_f80000gn/T/go-build869543369=/tmp/go-build -gno-record-gcc-switches -fno-common'
  • Exactly which command you ran
staticcheck ./
  • Output of the command and what's wrong with the output
main.go:13:6: func fn2 is unused (U1000)

(fn1 should also be detected)

  • Where we can read the code you're running Staticcheck on
package main

func main() {
	var fn1 func(int)
	fn1 = func(i int) {
		if i < 0 {
			return
		}
		fn1(i-1)
	}
}

func fn2(i int) {
	if i < 0 {
		return
	}
	fn2(i-1)
}
@seiyab seiyab added false-negative needs-triage Newly filed issue that needs triage labels Mar 29, 2024
@dominikh
Copy link
Owner

I'm afraid this is outside of unused's domain.Syntactically, fn1 is used. We could check for this in some other check, though.

@dominikh dominikh added enhancement and removed false-negative needs-triage Newly filed issue that needs triage labels Mar 29, 2024
@dominikh dominikh changed the title unused (U1000): false negative for recursive closure staticcheck: flag recursive closure that never gets used Mar 29, 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