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

x/tools/go/analysis/passes/unusedwrite: detect dead stores to local vars #67109

Open
adonovan opened this issue Apr 29, 2024 · 0 comments
Open
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@adonovan
Copy link
Member

During review of https://go.dev/cl/581555, @timothy-king pointed out that I had defined a local variable using an if/else statement and then failed to use it after the statement, something like this:

 func f(pass *Pass), filename string) {
 	readFile := pass.ReadFile
 	if readFile == nil {
 		readFile = os.ReadFile
 	}
 	os.ReadFile(filename) // oops, I meant readFile
 }

The assignment to readFile is a dead store. We should flag this is a likely error.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 29, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 29, 2024
@adonovan adonovan added Analysis Issues related to static analysis (vet, x/tools/go/analysis) and removed Tools This label describes issues relating to any tools in the x/tools repository. labels Apr 29, 2024
@cherrymui cherrymui added the NeedsFix The path to resolution is known, but the work has not been done. label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants