Skip to content

Commit

Permalink
array with pointer-to-type
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendrixMSFT committed Aug 15, 2022
1 parent 7d6ef2c commit 925d2a9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/go/cmd/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,25 @@ func unwrapStructFieldTypeName(field *ast.Field) string {
return ""
}

// start with the field expression
exp := field.Type

// if it's an array, get the element expression.
// current codegen doesn't support *[]Type so no need to handle it.
if at, ok := exp.(*ast.ArrayType); ok {
// FieldName []FieldType
// FieldName []*FieldType
exp = at.Elt
}

// from here we either have a pointer-to-type or type
var ident *ast.Ident
if se, ok := field.Type.(*ast.StarExpr); ok {
if se, ok := exp.(*ast.StarExpr); ok {
// FieldName *FieldType
ident, _ = se.X.(*ast.Ident)
} else if at, ok := field.Type.(*ast.ArrayType); ok {
// FieldName []FieldType
ident, _ = at.Elt.(*ast.Ident)
} else {
// FieldName FieldType
ident, _ = field.Type.(*ast.Ident)
ident, _ = exp.(*ast.Ident)
}

// !IsExported() is a hacky way to ignore primitive types
Expand Down

0 comments on commit 925d2a9

Please sign in to comment.