Skip to content

Commit

Permalink
Merge pull request #175 from abicky/issue174
Browse files Browse the repository at this point in the history
Fix panic that occurs when a struct has a blank field
  • Loading branch information
darccio authored Mar 3, 2021
2 parents ef53dc5 + 7c75920 commit aa32fec
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 aa32fec

Please sign in to comment.