jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.58k stars 489 forks source link

[Bug] Panic on SetMapIndex when using map[x]interface{} #79

Closed maeglindeveloper closed 3 years ago

maeglindeveloper commented 3 years ago

Reproducible Example

https://play.golang.org/p/RJOgBhY1oGo

Description

Hi everyone,

I'm facing again a panic using the CopyWithOptions() method. See above the example.

It seems this is related to map[x]interface{} @jinzhu

grount commented 3 years ago

Having the same issue on map[string]interface{}. panic: reflect: call of reflect.Value.SetMapIndex on interface Value

maeglindeveloper commented 3 years ago

@jinzhu any advice on this ? :)

rahulkhairwar commented 3 years ago

@jinzhu the below line doesn't actually set to's value to a map : to.Set(reflect.MakeMapWithSize(toType, from.Len())) Later, to.SetMapIndex(toKey, toValue) causes panic, as to is not of type map. Any way to resolve this?

jinzhu commented 3 years ago

This should been fixed in latest version