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/gopls: unusedparams analyzer reports false positive due to build tags #65479

Open
adonovan opened this issue Feb 2, 2024 · 1 comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) gopls/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Feb 2, 2024

xtools$ go run ./gopls/internal/analysis/unusedparams/cmd/main.go -c 3 ./gopls/internal/test/integration/fake
/Users/adonovan/w/xtools/gopls/internal/test/integration/fake/workdir.go:75:38: unused parameter: err
72	
73	// isWindowsErrLockViolation reports whether err is ERROR_LOCK_VIOLATION
74	// on Windows.
75	var isWindowsErrLockViolation = func(err error) bool { return false }
76	

The analysis believes that this function is assigned to a variable that is only ever used in call position--because it is never used at all. In fact it is used in non-call position, for an assignment to the variable, though only in a file tagged for GOOS=windows, which of course the analysis cannot see. Consequently it falsely reports that the parameter can be safely removed.

One possibility would be to observe that pass.IgnoredGoFiles contains one or more files, in particular files with build tags, and to conservatively assume that these extra files contain assignments to all variables such as isWindowsErrLockViolation.

This is really a representative for a whole class of built-tag-related analyzer problems.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Feb 2, 2024
@gopherbot gopherbot added this to the Unreleased milestone Feb 2, 2024
@adonovan adonovan added Analysis Issues related to static analysis (vet, x/tools/go/analysis) gopls/analysis Issues related to running analysis in gopls labels Feb 2, 2024
@findleyr
Copy link
Contributor

findleyr commented Feb 2, 2024

Moving this to the backlog, since this is a large category of problem that requires careful thought and planning.

@findleyr findleyr modified the milestones: Unreleased, Backlog Feb 2, 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) gopls/analysis Issues related to running analysis in gopls gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants