Skip to content

fix(join): declaration-of matches methods and function-local declarations - #971

Open
vignesh2027 wants to merge 1 commit into
DataDog:mainfrom
vignesh2027:fix/declaration-of-top-level
Open

vignesh2027 wants to merge 1 commit into
DataDog:mainfrom
vignesh2027:fix/declaration-of-top-level

Conversation

@vignesh2027

Copy link
Copy Markdown
Contributor

Why

The declaration-of join point is documented as matching top-level declarations, but it also matches two kinds of node that are not package-scope declarations.

A FuncDecl was matched on its name alone, so a method called Foo satisfied declaration-of: pkg.Foo. A ValueSpec was accepted whenever its parent was a GenDecl, and a GenDecl also wraps the var and const declarations inside a function body. A local variable that shares the name was matched as well.

What

Methods are skipped (Recv != nil), and the GenDecl of a ValueSpec must have the *dst.File as its parent.

TestDeclarationOf walks a small package and checks which nodes each join point matches: top-level vars, consts and functions still match, while methods, locals in nested blocks and closures, and types do not. The method and local cases fail on main.

I looked for open issues and PRs about declaration-of and found none.

…ions

The declaration-of join point is documented to match top-level declarations, but it
matched two other kinds of node.

A FuncDecl was matched on its name alone, so a method called Foo satisfied
declaration-of pkg.Foo even though it does not declare anything in the package scope.

A ValueSpec was accepted whenever its parent was a GenDecl. A GenDecl also wraps
the var and const declarations inside a function body, so a local variable that
happened to share the name was matched too.

Skip methods, and require the GenDecl of a ValueSpec to sit directly in the file.
@vignesh2027
vignesh2027 requested a review from a team as a code owner November 28, 2026 13:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant