From 46abde550172acb4471302c26313078d089a9d6a Mon Sep 17 00:00:00 2001 From: Morgan Pittkin Date: Tue, 3 Sep 2024 12:56:07 -0400 Subject: [PATCH] tweak code block for copying to a nil empty interface value --- copier.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/copier.go b/copier.go index 866c0e3..a2a2835 100644 --- a/copier.go +++ b/copier.go @@ -140,7 +140,8 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error) } // If possible, simply copy the struct - if from.Type().AssignableTo(to.Type()) { + //if from.Type().AssignableTo(to.Type()) && to.Kind() == reflect.Interface { + if from.Kind() == reflect.Struct && from.Type().AssignableTo(to.Type()) && reflect.TypeOf(to.Interface()) == nil { to.Set(from) return }