Skip to content

Commit

Permalink
Fix implicit aliasing issue in nested maps
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamradhakrishnan committed May 12, 2023
1 parent 20b9845 commit 766a447
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 766a447

Please sign in to comment.