diff --git a/pkg/deepcopy/testdata/cronjob_types.go b/pkg/deepcopy/testdata/cronjob_types.go index 567b2aecc..2bd3bb22a 100644 --- a/pkg/deepcopy/testdata/cronjob_types.go +++ b/pkg/deepcopy/testdata/cronjob_types.go @@ -125,6 +125,7 @@ type SpecificCases struct { MapWithNamedKeys map[TotallyAString]int `json:"mapWithNamedKeys"` MapToPtrToDeepCopyIntoRefType map[string]*DeepCopyIntoRef `json:"mapToPtrToDeepCopyIntoRefType"` MapToDeepCopyIntoRefType map[string]DeepCopyIntoRef `json:"mapToDeepCopyIntoRefType"` + MapNested map[string]map[string]string `json:"mapNested,omitempty"` // other slice types SliceToDeepCopyPtr []DeepCopyPtr `json:"sliceToDeepCopyPtr"` diff --git a/pkg/deepcopy/testdata/zz_generated.deepcopy.go b/pkg/deepcopy/testdata/zz_generated.deepcopy.go index 857c8add7..f09fe7d41 100644 --- a/pkg/deepcopy/testdata/zz_generated.deepcopy.go +++ b/pkg/deepcopy/testdata/zz_generated.deepcopy.go @@ -643,7 +643,8 @@ func (in *SpecificCases) DeepCopyInto(out *SpecificCases) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = make([]string, len(*in)) copy(*out, *in) } @@ -681,6 +682,24 @@ func (in *SpecificCases) DeepCopyInto(out *SpecificCases) { (*out)[key] = val.DeepCopy() } } + if in.MapNested != nil { + in, out := &in.MapNested, &out.MapNested + *out = make(map[string]map[string]string, len(*in)) + for key, val := range *in { + var outVal map[string]string + if val == nil { + (*out)[key] = nil + } else { + inVal := (*in)[key] + in, out := &inVal, &outVal + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + (*out)[key] = outVal + } + } if in.SliceToDeepCopyPtr != nil { in, out := &in.SliceToDeepCopyPtr, &out.SliceToDeepCopyPtr *out = make([]DeepCopyPtr, len(*in)) @@ -1518,7 +1537,8 @@ func (in *TestMaps) DeepCopyInto(out *TestMaps) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = new(string) **out = **in } @@ -1533,7 +1553,8 @@ func (in *TestMaps) DeepCopyInto(out *TestMaps) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = new(*string) if **in != nil { in, out := *in, *out @@ -1552,7 +1573,8 @@ func (in *TestMaps) DeepCopyInto(out *TestMaps) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = make(map[string]string, len(*in)) for key, val := range *in { (*out)[key] = val @@ -1569,7 +1591,8 @@ func (in *TestMaps) DeepCopyInto(out *TestMaps) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = new(map[string]string) if **in != nil { in, out := *in, *out @@ -1590,7 +1613,8 @@ func (in *TestMaps) DeepCopyInto(out *TestMaps) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = make([]string, len(*in)) copy(*out, *in) } @@ -1605,7 +1629,8 @@ func (in *TestMaps) DeepCopyInto(out *TestMaps) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = new([]string) if **in != nil { in, out := *in, *out @@ -1631,7 +1656,8 @@ func (in *TestMaps) DeepCopyInto(out *TestMaps) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = new(Ttest) (*in).DeepCopyInto(*out) } @@ -1961,7 +1987,8 @@ func (in *Ttest) DeepCopyInto(out *Ttest) { if val == nil { (*out)[key] = nil } else { - in, out := &val, &outVal + inVal := (*in)[key] + in, out := &inVal, &outVal *out = make(Slice, len(*in)) copy(*out, *in) } diff --git a/pkg/deepcopy/traverse.go b/pkg/deepcopy/traverse.go index 9658e1052..863408873 100644 --- a/pkg/deepcopy/traverse.go +++ b/pkg/deepcopy/traverse.go @@ -374,7 +374,8 @@ func (c *copyMethodMaker) genMapDeepCopy(actualName *namingInfo, mapType *types. c.IfElse("val == nil", func() { c.Line("(*out)[key] = nil") }, func() { - c.Line("in, out := &val, &outVal") + c.Line("inVal := (*in)[key]") + c.Line("in, out := &inVal, &outVal") c.genDeepCopyIntoBlock(&namingInfo{typeInfo: mapType.Elem()}, mapType.Elem()) }) c.Line("(*out)[key] = outVal")