mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(maputil): map slices into array destinations (#371)
This commit is contained in:
1 parent
4db163b4b7
commit
65806afc7d
2 files changed
+16
-3
No files matched your search
+6
-3
@@ -582,9 +582,12 @@ func convertSlice(src reflect.Value, dst reflect.Value) error {
|
||||
return fmt.Errorf("error type:%s", dst.Type().String())
|
||||
}
|
||||
l := src.Len()
|
||||
target := reflect.MakeSlice(dst.Type(), l, l)
|
||||
if dst.CanSet() {
|
||||
dst.Set(target)
|
||||
if dst.Kind() == reflect.Array {
|
||||
if l > dst.Len() {
|
||||
return fmt.Errorf("source length %d exceeds destination length %d", l, dst.Len())
|
||||
}
|
||||
} else if dst.CanSet() {
|
||||
dst.Set(reflect.MakeSlice(dst.Type(), l, l))
|
||||
}
|
||||
for i := 0; i < l; i++ {
|
||||
srcValue := src.Index(i)
|
||||
|
||||
Reference in new issue
Block a user