Skip to content

Commit

Permalink
Use objectpath for object labels where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-mc committed Jun 12, 2024
1 parent 1ebe8c1 commit 6c7302e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/extractor/trap/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions go/extractor/trap/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"go/types"

"github.com/github/codeql-go/extractor/util"
"golang.org/x/tools/go/types/objectpath"
)

// Label represents a label
Expand Down Expand Up @@ -157,7 +158,15 @@ func (l *Labeler) ScopedObjectID(object types.Object, getTypeLabel func() Label)
// referenced from other files via their method
methlbl, _ := l.MethodID(meth, getTypeLabel())
label, _ = l.ReceiverObjectID(object, methlbl)
} else if path, err := objectpath.For(object); err == nil {
// If we can, use the object path as the label. This is needed
// for type parameters. Note that `objectpath` returns an error
// for non-exported objects.
label = l.GlobalID(fmt.Sprintf("%v,{%s};object", object.Pkg().Path(), path))
} else {
// Otherwise, construct a label based on the scope and the object's name.
// If the scope is not package scope then it will be given a fresh label,
// which will be different when it is referenced from different packages.
scopeLbl := l.ScopeID(scope, object.Pkg())
label = l.GlobalID(fmt.Sprintf("{%v},%s;object", scopeLbl, object.Name()))
}
Expand Down

0 comments on commit 6c7302e

Please sign in to comment.