Skip to content

Commit

Permalink
Merge pull request #810 from shyamradhakrishnan/shyamradhakrishnan-fi…
Browse files Browse the repository at this point in the history
…x-809

🐛 Fix implicit aliasing issue in nested maps
  • Loading branch information
k8s-ci-robot authored Aug 10, 2023
2 parents 0089762 + 766a447 commit d18ba5c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/deepcopy/testdata/cronjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
45 changes: 36 additions & 9 deletions pkg/deepcopy/testdata/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/deepcopy/traverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d18ba5c

Please sign in to comment.