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.
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 intofunc indirectType
, it attempts to call theKind()
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 theto
value being an empty interface, to simply callto.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 theOptions.DeepCopy
value.