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

Copy to nil empty interface #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mpittkin
Copy link

@mpittkin mpittkin commented Sep 5, 2024

We have been using an old version of this package, and our attempts to update it to a newer version have failed because when copying a struct value to an empty interface with a nil value, a panic is caused.

In copier.go#150, reflect.TypeOf(to.Interface()) returns nil because it's an empty interface, and when it passes that nil value into func indirectType, it attempts to call the Kind() method on the nil value, causing the panic.

The change I'm proposing is that in the case of the from value being a struct and the to value being an empty interface, to simply call to.Set(from) and then return.

I'm fairly confident this won't break any existing client code since the current behavior in this case is to panic. But I'm very open to suggestions on how this might better be accomplished, especially in the case of from types other than structs, or how to best honor things like the Options.DeepCopy value.

…, simply copy the value

This avoids a panic when attempting to examine the type of 'from'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant