x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags (or assembly) #71686
Labels
Analysis
Issues related to static analysis (vet, x/tools/go/analysis)
BugReport
Issues describing a possible bug in the Go implementation.
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
gopls' unusedfunc analysis may report spurious "function f is unused" diagnostics when uses exist but only in build-tagged files of the same package that are ignored in the current configuration. See my incorrect delayed comment on https://go.dev/cl/630415 for an example of the confusion.
@cherrymui suggested that the analyzer should offer to move the declaration into the tagged, ignored file that needs it, but that presupposes that our analysis is aware of the ignored file, which it isn't, and which is in general a challenging problem.
But still we could do better than the status quo: if the package contains ignored files, we could qualify the diagnostic with some reference to the build tag. It could be generic such as "(may depend on build tags)", or specific such as "(assuming !purego tags)", where the latter computes a falsifying tag assignment. (If we go the latter route, the analysis framework should provide helpers to do the heavy lifting.)
In principle this should be done for any analyzer whose correctness depends on the package as a whole, not just the current file.
Related: in
runtime
, this analyzer reports a number of false positives on unreferenced intrinsics--functions that, though never referenced from Go source in the runtime, are referenced indirectly from compiler-generated object code--and on functions that are referenced only from assembly code. The unusedfuncs analyzer should suppress diagnostics for intrinsics, and parse (all?) assembly files in the package looking for references.The text was updated successfully, but these errors were encountered: