diff --git a/internal/generator/method/method.go b/internal/generator/method/method.go index f776237..e94528a 100644 --- a/internal/generator/method/method.go +++ b/internal/generator/method/method.go @@ -226,6 +226,16 @@ func toType(t types.Type, variadic bool) (jen.Code, error) { return jen.Index().Add(elemType), nil case named: return jen.Id(v.Name()), nil + case *types.Map: + keyType, err := toType(v.Key(), false) + if err != nil { + return nil, err + } + elemType, err := toType(v.Elem(), false) + if err != nil { + return nil, err + } + return jen.Map(keyType).Add(elemType), nil default: return nil, fmt.Errorf("type not handled: %T", v) } diff --git a/internal/generator/method/method_test.go b/internal/generator/method/method_test.go index cf10a92..99db205 100644 --- a/internal/generator/method/method_test.go +++ b/internal/generator/method/method_test.go @@ -154,6 +154,23 @@ func TestNewMethod(t *testing.T) { ReturnTypes: []jen.Code{jen.Id("interface{}")}, }, }, + { + name: "Fn(arg map[string]interface{}) map[string]int", + args: args{ + name: "Fn", + signature: types.NewSignature(nil, + types.NewTuple(types.NewVar(token.NoPos, nil, "arg", types.NewMap(types.Typ[types.String], types.NewInterfaceType(nil, nil)))), + types.NewTuple(types.NewVar(token.NoPos, nil, "", types.NewMap(types.Typ[types.String], types.Typ[types.Int]))), + false), + }, + want: &method.Method{ + Name: "Fn", + HasContext: false, + ParameterNames: []string{"arg0"}, + ParametersNameAndType: []jen.Code{jen.Id("arg0").Add(jen.Map(jen.Id("string")).Add(jen.Id("interface{}")))}, + ReturnTypes: []jen.Code{jen.Map(jen.Id("string")).Add(jen.Id("int"))}, + }, + }, } for _, tt := range tests {