Skip to content

Commit cd31f63

Browse files
committed
Distinguish types with and without explicit aliases in the type-label cache
1 parent 16d1a95 commit cd31f63

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

go/extractor/extractor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,8 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
16891689
}
16901690

16911691
func getTypeLabelWithFlags(tw *trap.Writer, tp types.Type, transparentAliases bool) (trap.Label, bool) {
1692-
lbl, exists := tw.Labeler.TypeLabels[tp]
1692+
typeLabelKey := trap.TypeLabelsKey{Type: tp, TransparentAliases: transparentAliases}
1693+
lbl, exists := tw.Labeler.TypeLabels[typeLabelKey]
16931694
if !exists {
16941695
switch tp := tp.(type) {
16951696
case *types.Basic:
@@ -1833,7 +1834,7 @@ func getTypeLabelWithFlags(tw *trap.Writer, tp types.Type, transparentAliases bo
18331834
default:
18341835
log.Fatalf("(getTypeLabel) unexpected type %T", tp)
18351836
}
1836-
tw.Labeler.TypeLabels[tp] = lbl
1837+
tw.Labeler.TypeLabels[typeLabelKey] = lbl
18371838
}
18381839
return lbl, exists
18391840
}

go/extractor/trap/labels.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ func (lbl *Label) String() string {
1919
return lbl.id
2020
}
2121

22+
type TypeLabelsKey struct {
23+
Type types.Type
24+
TransparentAliases bool
25+
}
26+
2227
// Labeler is used to represent labels for a file. It is used to write
2328
// associate objects with labels.
2429
type Labeler struct {
2530
tw *Writer
2631

2732
nextid int
2833
fileLabel Label
29-
nodeLabels map[interface{}]Label // labels associated with AST nodes
30-
scopeLabels map[*types.Scope]Label // labels associated with scopes
31-
objectLabels map[types.Object]Label // labels associated with objects (that is, declared entities)
32-
TypeLabels map[types.Type]Label // labels associated with types
34+
nodeLabels map[interface{}]Label // labels associated with AST nodes
35+
scopeLabels map[*types.Scope]Label // labels associated with scopes
36+
objectLabels map[types.Object]Label // labels associated with objects (that is, declared entities)
37+
TypeLabels map[TypeLabelsKey]Label // labels associated with types
3338
keyLabels map[string]Label
3439
}
3540

@@ -41,7 +46,7 @@ func newLabeler(tw *Writer) *Labeler {
4146
make(map[interface{}]Label),
4247
make(map[*types.Scope]Label),
4348
make(map[types.Object]Label),
44-
make(map[types.Type]Label),
49+
make(map[TypeLabelsKey]Label),
4550
make(map[string]Label),
4651
}
4752
}

0 commit comments

Comments
 (0)