Conversation
namesForExcludeCheck only computed a name for calls with an explicit selector (pkg.Func() / recv.Method()). A call to a package-level function from within its own package has no selector -- it is a plain identifier -- so such calls were never matched against -exclude, even though the exact same function called from an importing package (pkg.FirstFunc()) was correctly excluded. Resolve the identifier directly via types.Info.ObjectOf and compute its FullName() the same way the selector branch does, so in-package calls are excluded on equal footing with cross-package calls. Fixes kisielk#251
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #251.
Bug
-exclude(checker.Exclusions.Symbols) matches a called function's fully-qualified name, but the name was only ever computed for calls that go through a selector expression (pkg.Func()/recv.Method(), handled inselectorAndFunc). A call to a package-level function from within its own package has no selector — it's a plain identifier (FirstFunc(), notfirst.FirstFunc()) — sonamesForExcludeCheckreturnednilfor it and the exclusion never matched, even though the same function is correctly excluded when called from an importing package.Fix
When the selector lookup fails, also try resolving the call as a plain identifier via
typesInfo.ObjectOf, and computeFullName()the same way the selector branch does. This is purely additive: the existing selector path is untouched, and non-function identifiers (okstays false) fall through exactly as before.Testing
Added
TestSamePackageFunctionExclude, modeled on the existingTestTypeParameterizedFunctionExclude: two synthetic packages, one (first) declaringFirstFuncand calling it internally (unqualified) fromThirdFunc, the other (second) calling it externally viafirst.FirstFunc().Without the fix, excluding
samepkgtest/first.FirstFuncstill leaves the in-package call flagged — verified this fails for the expected reason:With the fix, both calls are excluded and the full package test suite (
go test ./...) passes.