Skip to content

Commit c4c89f7

Browse files
ntoofuk8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
Update marker.Collector to fix bug of markers
Markers are saved per `*ast.TypeSpec`, which is specific to `Package` object. `*ast.TypeSpec` in another `Package` object is different even when the `Package.ID` is the same, and so collected markers cannot be reused for another `Package` object. Therefore, `Package` itself is used as a key for cache of markers insetead of `Package.ID`. For more details about the bug, see #783.
1 parent ce59fd8 commit c4c89f7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

pkg/markers/collect.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
type Collector struct {
3232
*Registry
3333

34-
byPackage map[string]map[ast.Node]MarkerValues
34+
byPackage map[*loader.Package]map[ast.Node]MarkerValues
3535
mu sync.Mutex
3636
}
3737

@@ -53,7 +53,7 @@ func (c *Collector) init() {
5353
c.Registry = &Registry{}
5454
}
5555
if c.byPackage == nil {
56-
c.byPackage = make(map[string]map[ast.Node]MarkerValues)
56+
c.byPackage = make(map[*loader.Package]map[ast.Node]MarkerValues)
5757
}
5858
}
5959

@@ -75,7 +75,7 @@ func (c *Collector) init() {
7575
func (c *Collector) MarkersInPackage(pkg *loader.Package) (map[ast.Node]MarkerValues, error) {
7676
c.mu.Lock()
7777
c.init()
78-
if markers, exist := c.byPackage[pkg.ID]; exist {
78+
if markers, exist := c.byPackage[pkg]; exist {
7979
c.mu.Unlock()
8080
return markers, nil
8181
}
@@ -91,8 +91,7 @@ func (c *Collector) MarkersInPackage(pkg *loader.Package) (map[ast.Node]MarkerVa
9191

9292
c.mu.Lock()
9393
defer c.mu.Unlock()
94-
c.byPackage[pkg.ID] = markers
95-
94+
c.byPackage[pkg] = markers
9695
return markers, nil
9796
}
9897

0 commit comments

Comments
 (0)