Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 59aa742

Browse files
owen-mcsmowton
authored andcommitted
Add comments about entities without a parent scope
1 parent 9abc7ea commit 59aa742

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

extractor/extractor.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ func extractScopeLocation(tw *trap.Writer, scope *types.Scope, lbl trap.Label) {
727727
}
728728

729729
// extractScopes extracts symbol table information for the package scope and all local scopes
730-
// of the given package
730+
// of the given package. Note that this will not encounter methods or struct fields as
731+
// they do not have a parent scope.
731732
func extractScopes(tw *trap.Writer, nd *ast.File, pkg *packages.Package) {
732733
pkgScopeLabel := extractPackageScope(tw, pkg)
733734
fileScope := pkg.TypesInfo.Scopes[nd]
@@ -1457,7 +1458,9 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
14571458
for i := 0; i < tp.NumFields(); i++ {
14581459
field := tp.Field(i)
14591460

1460-
// ensure the field is associated with a label
1461+
// ensure the field is associated with a label - note that
1462+
// struct fields do not have a parent scope, so they are not
1463+
// dealt with by `extractScopes`
14611464
fieldlbl, exists := tw.Labeler.FieldID(field, i, lbl)
14621465
if !exists {
14631466
extractObject(tw, field, fieldlbl)
@@ -1479,6 +1482,8 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
14791482
for i := 0; i < tp.NumMethods(); i++ {
14801483
meth := tp.Method(i)
14811484

1485+
// Note that methods do not have a parent scope, so they are
1486+
// not dealt with by `extractScopes`
14821487
extractMethod(tw, meth)
14831488

14841489
extractComponentType(tw, lbl, i, meth.Name(), meth.Type())
@@ -1537,7 +1542,8 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
15371542
dbscheme.TypeObjectTable.Emit(tw, lbl, entitylbl)
15381543
}
15391544

1540-
// ensure all methods have labels
1545+
// ensure all methods have labels - note that methods do not have a
1546+
// parent scope, so they are not dealt with by `extractScopes`
15411547
for i := 0; i < origintp.NumMethods(); i++ {
15421548
meth := origintp.Method(i)
15431549

0 commit comments

Comments
 (0)