@@ -13,11 +13,11 @@ import (
13
13
"reflect"
14
14
)
15
15
16
- func isMergeableField (dst reflect.Value ) (exported bool ) {
16
+ func hasMergeableFields (dst reflect.Value ) (exported bool ) {
17
17
for i , n := 0 , dst .NumField (); i < n ; i ++ {
18
18
field := dst .Type ().Field (i )
19
19
if field .Anonymous && dst .Field (i ).Kind () == reflect .Struct {
20
- exported = exported || isMergeableField (dst .Field (i ))
20
+ exported = exported || hasMergeableFields (dst .Field (i ))
21
21
} else if isExportedComponent (& field ) {
22
22
exported = exported || len (field .PkgPath ) == 0
23
23
}
@@ -45,6 +45,7 @@ type Config struct {
45
45
overwriteWithEmptyValue bool
46
46
overwriteSliceWithEmptyValue bool
47
47
sliceDeepCopy bool
48
+ debug bool
48
49
}
49
50
50
51
type Transformers interface {
@@ -87,7 +88,7 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
87
88
88
89
switch dst .Kind () {
89
90
case reflect .Struct :
90
- if isMergeableField (dst ) {
91
+ if hasMergeableFields (dst ) {
91
92
for i , n := 0 , dst .NumField (); i < n ; i ++ {
92
93
if err = deepMerge (dst .Field (i ), src .Field (i ), visited , depth + 1 , config ); err != nil {
93
94
return
@@ -236,15 +237,6 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
236
237
break
237
238
}
238
239
239
- if dst .Kind () != reflect .Ptr && src .Type ().AssignableTo (dst .Type ()) {
240
- if dst .IsNil () || overwrite {
241
- if dst .CanSet () && (overwrite || isEmptyValue (dst )) {
242
- dst .Set (src )
243
- }
244
- }
245
- break
246
- }
247
-
248
240
if src .Kind () != reflect .Interface {
249
241
if dst .IsNil () || (src .Kind () != reflect .Ptr && overwrite ) {
250
242
if dst .CanSet () && (overwrite || isEmptyValue (dst )) {
@@ -268,11 +260,22 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
268
260
if dst .CanSet () && (overwrite || isEmptyValue (dst )) {
269
261
dst .Set (src )
270
262
}
271
- } else if err = deepMerge (dst .Elem (), src .Elem (), visited , depth + 1 , config ); err != nil {
272
- return
263
+ break
264
+ }
265
+
266
+ if dst .Elem ().Kind () == src .Elem ().Kind () {
267
+ if err = deepMerge (dst .Elem (), src .Elem (), visited , depth + 1 , config ); err != nil {
268
+ return
269
+ }
270
+ break
273
271
}
274
272
default :
275
- mustSet := (! isEmptyValue (src ) || overwriteWithEmptySrc ) && (overwrite || isEmptyValue (dst ))
273
+ mustSet := (isEmptyValue (dst ) || overwrite ) && (! isEmptyValue (src ) || overwriteWithEmptySrc )
274
+ v := fmt .Sprintf ("%v" , src )
275
+ if v == "TestIssue106" {
276
+ fmt .Println (mustSet )
277
+ fmt .Println (dst .CanSet ())
278
+ }
276
279
if mustSet {
277
280
if dst .CanSet () {
278
281
dst .Set (src )
0 commit comments