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
{{ message }}
Repository navigation
x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags (or assembly) #71686
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.
changed the title [-]x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags[/-][+]x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags (or assembly)[/+]on Feb 13, 2025
Activity
gabyhelp commentedon Feb 12, 2025
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
[-]x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags[/-][+]x/tools/gopls/internal/analysis/unusedfunc: spurious reports in packages that use build tags (or assembly)[/+]gopherbot commentedon Feb 13, 2025
Change https://go.dev/cl/649256 mentions this issue:
gopls/internal/analysis/unusedfunc: don't report runtime intrinsicsgopherbot commentedon Jul 29, 2025
Change https://go.dev/cl/691496 mentions this issue:
gopls/internal/analysis/unusedfunc: skip stdgopls/internal/analysis/unusedfunc: skip std