Skip to content

Commit d18ba5c

Browse files
authored
Merge pull request #810 from shyamradhakrishnan/shyamradhakrishnan-fix-809
🐛 Fix implicit aliasing issue in nested maps
2 parents 0089762 + 766a447 commit d18ba5c

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

pkg/deepcopy/testdata/cronjob_types.go

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ type SpecificCases struct {
125125
MapWithNamedKeys map[TotallyAString]int `json:"mapWithNamedKeys"`
126126
MapToPtrToDeepCopyIntoRefType map[string]*DeepCopyIntoRef `json:"mapToPtrToDeepCopyIntoRefType"`
127127
MapToDeepCopyIntoRefType map[string]DeepCopyIntoRef `json:"mapToDeepCopyIntoRefType"`
128+
MapNested map[string]map[string]string `json:"mapNested,omitempty"`
128129

129130
// other slice types
130131
SliceToDeepCopyPtr []DeepCopyPtr `json:"sliceToDeepCopyPtr"`

pkg/deepcopy/testdata/zz_generated.deepcopy.go

+36-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deepcopy/traverse.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ func (c *copyMethodMaker) genMapDeepCopy(actualName *namingInfo, mapType *types.
374374
c.IfElse("val == nil", func() {
375375
c.Line("(*out)[key] = nil")
376376
}, func() {
377-
c.Line("in, out := &val, &outVal")
377+
c.Line("inVal := (*in)[key]")
378+
c.Line("in, out := &inVal, &outVal")
378379
c.genDeepCopyIntoBlock(&namingInfo{typeInfo: mapType.Elem()}, mapType.Elem())
379380
})
380381
c.Line("(*out)[key] = outVal")

0 commit comments

Comments
 (0)