diff --git a/main.go b/main.go index a82331d..6ec2100 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,20 @@ func getKeyAndElementType(pkg *ast.Package, name string, typeSpec *ast.TypeSpec) if t, ok := typeSpec.Type.(*ast.ArrayType); ok { explorer := NewTypeExplorer(pkg, getIdentName(t.Elt)) + switch v := t.Elt.(type) { + case *ast.Ident: + if v == nil || v.Obj == nil { + break + } + + if ts, ok := v.Obj.Decl.(*ast.TypeSpec); ok { + if _, ok := ts.Type.(*ast.InterfaceType); ok { + explorer.IsInterface = true + } + } + + } + return pkgName, "", getIdentName(t.Elt), explorer } @@ -209,7 +223,7 @@ func main() { // If its a pointer we need to replace '*' -> '&' when // instantiating. - if elementType[0] == '*' { + if elementType[0] == '*' || explorer.IsInterface { zeroValue = "nil" } diff --git a/type_explorer.go b/type_explorer.go index 064989e..792e055 100644 --- a/type_explorer.go +++ b/type_explorer.go @@ -6,8 +6,9 @@ import ( ) type TypeExplorer struct { - TypeName string - Methods []string + TypeName string + Methods []string + IsInterface bool } func NewTypeExplorer(pkg *ast.Package, typeName string) *TypeExplorer {