Skip to content

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

Open
@adonovan

Description

@adonovan

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 as a likely error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions