diff --git a/cmd/libs/go2idl/deepcopy-gen/generators/deepcopy.go b/cmd/libs/go2idl/deepcopy-gen/generators/deepcopy.go index edaf75627b3..3f11e8f49f3 100644 --- a/cmd/libs/go2idl/deepcopy-gen/generators/deepcopy.go +++ b/cmd/libs/go2idl/deepcopy-gen/generators/deepcopy.go @@ -355,10 +355,17 @@ func (g *genDeepCopy) doBuiltin(t *types.Type, sw *generator.SnippetWriter) { func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) { sw.Do("*out = make($.|raw$)\n", t) if t.Key.IsAssignable() { - sw.Do("for key, val := range in {\n", nil) - if t.Elem.IsAssignable() { + switch { + case t.Elem.IsAnonymousStruct(): + sw.Do("for key := range in {\n", nil) + sw.Do("(*out)[key] = struct{}{}\n", nil) + sw.Do("}\n", nil) + case t.Elem.IsAssignable(): + sw.Do("for key, val := range in {\n", nil) sw.Do("(*out)[key] = val\n", nil) - } else { + sw.Do("}\n", nil) + default: + sw.Do("for key, val := range in {\n", nil) if g.canInlineTypeFn(g.context, t.Elem) { sw.Do("newVal := new($.|raw$)\n", t.Elem) funcName := g.funcNameTmpl(t.Elem) @@ -373,13 +380,14 @@ func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) { sw.Do("(*out)[key] = newVal.($.|raw$)\n", t.Elem) sw.Do("}\n", nil) } + sw.Do("}\n", nil) } } else { // TODO: Implement it when necessary. sw.Do("for range in {\n", nil) sw.Do("// FIXME: Copying unassignable keys unsupported $.|raw$\n", t.Key) + sw.Do("}\n", nil) } - sw.Do("}\n", nil) } func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) { diff --git a/cmd/libs/go2idl/types/types.go b/cmd/libs/go2idl/types/types.go index 7f25db15219..23693fdafaa 100644 --- a/cmd/libs/go2idl/types/types.go +++ b/cmd/libs/go2idl/types/types.go @@ -290,6 +290,12 @@ func (t *Type) IsAssignable() bool { return t.Kind == Builtin || (t.Kind == Alias && t.Underlying.Kind == Builtin) } +// IsAnonymousStruct returns true if the type is an anonymous struct or an alias +// to an anonymous struct. +func (t *Type) IsAnonymousStruct() bool { + return (t.Kind == Struct && t.Name.Name == "struct{}") || (t.Kind == Alias && t.Underlying.IsAnonymousStruct()) +} + // A single struct member type Member struct { // The name of the member.