Skip to content

Commit 693e330

Browse files
committed
refactor(analysis): update TypeAwareMarkerCollectionForField to support pointer dereferencing
1 parent bc7fd32 commit 693e330

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/analysis/utils/utils.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,23 @@ func isInPassPackage(pass *analysis.Pass, namedType *types.Named) bool {
122122
// TypeAwareMarkerCollectionForField collects the markers for a given field into a single markers.MarkerSet.
123123
// If the field has a type that is not a basic type (i.e a custom type) then it will also gather any markers from
124124
// the type and include them in the markers.MarkerSet that is returned.
125+
// It will look through *ast.StarExpr to the underlying type.
125126
// Markers on the type will always come before markers on the field in the list of markers for an identifier.
126127
func TypeAwareMarkerCollectionForField(pass *analysis.Pass, markersAccess markers.Markers, field *ast.Field) markers.MarkerSet {
127128
markers := markersAccess.FieldMarkers(field)
128129

129-
ident, ok := field.Type.(*ast.Ident)
130+
var underlyingType ast.Expr
131+
132+
switch t := field.Type.(type) {
133+
case *ast.Ident:
134+
underlyingType = t
135+
case *ast.StarExpr:
136+
underlyingType = t.X
137+
default:
138+
return markers
139+
}
140+
141+
ident, ok := underlyingType.(*ast.Ident)
130142
if !ok {
131143
return markers
132144
}

0 commit comments

Comments
 (0)