Skip to content

Commit 024bb3e

Browse files
committed
hadnle StartExpr
Signed-off-by: sivchari <shibuuuu5@gmail.com>
1 parent 97ea957 commit 024bb3e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/analysis/utils/utils.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,22 @@ func LookupTypeSpec(pass *analysis.Pass, ident *ast.Ident) (*ast.TypeSpec, bool)
7979

8080
// FieldName returns the name of the field. If the field has a name, it returns that name.
8181
// If the field is embedded and it can be converted to an identifier, it returns the name of the identifier.
82+
// If it doesn't have a name and can't be converted to an identifier, it returns an empty string.
8283
func FieldName(field *ast.Field) string {
8384
if len(field.Names) > 0 && field.Names[0] != nil {
8485
return field.Names[0].Name
8586
}
8687

87-
ident, ok := field.Type.(*ast.Ident)
88-
if !ok {
89-
return ""
88+
switch typ := field.Type.(type) {
89+
case *ast.Ident:
90+
return typ.Name
91+
case *ast.StarExpr:
92+
if ident, ok := typ.X.(*ast.Ident); ok {
93+
return ident.Name
94+
}
9095
}
9196

92-
return ident.Name
97+
return ""
9398
}
9499

95100
func getFilesForType(pass *analysis.Pass, ident *ast.Ident) (*token.File, *ast.File) {

0 commit comments

Comments
 (0)