Skip to content

Commit 48704a5

Browse files
committed
Ensure markersets are copied on read
1 parent b78c0ea commit 48704a5

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

pkg/analysis/helpers/markers/analyzer.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,25 @@ type markers struct {
5959
// FieldMarkers return the appropriate MarkerSet for the field,
6060
// or an empty MarkerSet if the appropriate MarkerSet isn't found.
6161
func (m *markers) FieldMarkers(field *ast.Field) MarkerSet {
62-
fMarkers, ok := m.fieldMarkers[field]
63-
if !ok {
64-
return NewMarkerSet()
65-
}
62+
fMarkers := m.fieldMarkers[field]
6663

67-
return fMarkers
64+
return NewMarkerSet(fMarkers.UnsortedList()...)
6865
}
6966

7067
// StructMarkers returns the appropriate MarkerSet if found, else
7168
// it returns an empty MarkerSet.
7269
func (m *markers) StructMarkers(sTyp *ast.StructType) MarkerSet {
73-
sMarkers, ok := m.structMarkers[sTyp]
74-
if !ok {
75-
return NewMarkerSet()
76-
}
70+
sMarkers := m.structMarkers[sTyp]
7771

78-
return sMarkers
72+
return NewMarkerSet(sMarkers.UnsortedList()...)
7973
}
8074

8175
// TypeMarkers return the appropriate MarkerSet for the type,
8276
// or an empty MarkerSet if the appropriate MarkerSet isn't found.
8377
func (m *markers) TypeMarkers(typ *ast.TypeSpec) MarkerSet {
84-
tMarkers, ok := m.typeMarkers[typ]
85-
if !ok {
86-
return NewMarkerSet()
87-
}
78+
tMarkers := m.typeMarkers[typ]
8879

89-
return tMarkers
80+
return NewMarkerSet(tMarkers.UnsortedList()...)
9081
}
9182

9283
func (m *markers) insertFieldMarkers(field *ast.Field, ms MarkerSet) {
@@ -377,3 +368,14 @@ func (ms MarkerSet) HasWithExpressions(identifier string, expressions map[string
377368

378369
return false
379370
}
371+
372+
// UnsortedList returns a list of the markers, in no particular order.
373+
func (ms MarkerSet) UnsortedList() []Marker {
374+
markers := []Marker{}
375+
376+
for _, marker := range ms {
377+
markers = append(markers, marker...)
378+
}
379+
380+
return markers
381+
}

0 commit comments

Comments
 (0)