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

🐛 Guard before type assertion #1119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/deepcopy/testdata/cronjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ type SpecificCases struct {

// Case: kubernetes-sigs/controller-tools#262 part 2 (see type definition)
StringMap MapOfStrings `json:"stringMap"`

// Case: kubernetes-sigs/controller-tools#813
StringAlias StringAlias `json:"stringAlias,omitempty"`
}

type StringAlias = string

// Test aliases to basic types
type TotallyAString string

Expand Down
13 changes: 7 additions & 6 deletions pkg/deepcopy/traverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,15 @@ func shouldBeCopied(pkg *loader.Package, info *markers.TypeInfo) bool {
return false
}

// according to gengo, everything named is an alias, except for an alias to a pointer,
// which is just a pointer, afaict. Just roll with it.
if asPtr, isPtr := typeInfo.(*types.Named).Underlying().(*types.Pointer); isPtr {
typeInfo = asPtr
}

lastType := typeInfo
if _, isNamed := typeInfo.(*types.Named); isNamed {
// according to gengo, everything named is an alias, except for an alias to a pointer,
// which is just a pointer, afaict. Just roll with it.
if asPtr, isPtr := typeInfo.(*types.Named).Underlying().(*types.Pointer); isPtr {
lastType = asPtr
typeInfo = asPtr
}

// if it has a manual deepcopy or deepcopyinto, we're fine
if hasAnyDeepCopyMethod(pkg, typeInfo) {
return true
Expand Down
Loading