Skip to content

Commit

Permalink
Fix panic that occurs when a struct has a blank field
Browse files Browse the repository at this point in the history
This commit fixes #174.
  • Loading branch information
abicky committed Jan 27, 2021
1 parent cd55aea commit 7c75920
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions issue174_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mergo_test

import (
"testing"

"github.com/imdario/mergo"
)

type structWithBlankField struct {
_ struct{}
A struct{}
}

func TestIssue174(t *testing.T) {
dst := structWithBlankField{}
src := structWithBlankField{}

if err := mergo.Merge(&dst, src, mergo.WithOverride); err != nil {
t.Error(err)
}
}
2 changes: 1 addition & 1 deletion merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
}
}
} else {
if (isReflectNil(dst) || overwrite) && (!isEmptyValue(src) || overwriteWithEmptySrc) {
if dst.CanSet() && (isReflectNil(dst) || overwrite) && (!isEmptyValue(src) || overwriteWithEmptySrc) {
dst.Set(src)
}
}
Expand Down

0 comments on commit 7c75920

Please sign in to comment.