Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix implicit aliasing issue in nested maps #810

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you a lot for the contribution 🥇
Could you please ensure that the change/issue is also covered with a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @camilamacedo86 I have added a nested map in cronjob_types.go and that fields and other fields are calling this new line. I hope that will cover as a test case. Can you suggest if I need to add test cases in other places as well?

c.genDeepCopyIntoBlock(&namingInfo{typeInfo: mapType.Elem()}, mapType.Elem())
})
c.Line("(*out)[key] = outVal")
Expand Down