You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
ruilya
added
gopls
Issues related to the Go language server, gopls.
Tools
This label describes issues relating to any tools in the x/tools repository.
labels
Jan 31, 2024
The unusedparams analysis, like most gopls analyzers, uses the golang.org/x/tools/go/analysis framework for modular analysis, which is analogous to separate compilation in a compiler. That means that the analysis of a given package can access the package itself, and summaries of information obtained from the package's dependencies, but it cannot access information from packages that import the current package.
For the specific problem of unused parameters, that means it cannot report that a parameter of an exported function (such as your F) is unused, because another package could assign F to a variable of type func (int) (or a method to an interface of type interface{F(int)}), in which case applying the suggested fix to remove the parameter would break the program. The fix would be unsound.
Until recently, the unusedparams checker was disabled by default because it made exactly that unsound assumption, causing it to frequently give harmful advice. We recently rewrote it so that it is completely sound (no false positives), allowing us to enable it by default. Of course this means that may miss some true positives, but we believe that is the better trade-off.
So this is working as intended. You may find it helpful to periodically run a global analysis tool for detecting dead code, unused fields, unused parameters and so on, as such tools may have better precision; but gopls cannot run such analyses in real time.
adonovan
changed the title
x/tools/gopls: unusedparams analysis does not check
x/tools/gopls: unusedparams analysis does not check exported functions
Feb 1, 2024
gopls version
v0.14.2
go env
What did you do?
Defining a function that does something (for e.g. fmt.Println("sometext")) but is not using it's arguments does not raise a warning.
What did you see happen?
No diagnostic is generated about unused function parameter. Other analyses are ran and displayed as expected.
What did you expect to see?
Warning about unused parameter.
Editor and settings
nvim v0.9.5
full configuration: https://github.com/ilya-rusyanov/nvim-config
Logs
No response
The text was updated successfully, but these errors were encountered: