Skip to content

Commit d9fe39d

Browse files
committed
Extractor: add comment about tw.Package.TypesInfo.Defs
1 parent 7209617 commit d9fe39d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

go/extractor/extractor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,10 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int) {
870870
kind = dbscheme.IdentExpr.Index()
871871
dbscheme.LiteralsTable.Emit(tw, lbl, expr.Name, expr.Name)
872872
def := tw.Package.TypesInfo.Defs[expr]
873+
// Note that there are some cases where `expr` is in the map but `def`
874+
// is nil. The docs for `tw.Package.TypesInfo.Defs` give the following
875+
// examples: the package name in package clauses, or symbolic variables
876+
// `t` in `t := x.(type)` of type switch headers.
873877
if def != nil {
874878
defTyp := extractType(tw, def.Type())
875879
objlbl, exists := tw.Labeler.LookupObjectID(def, defTyp)

0 commit comments

Comments
 (0)