diff --git a/README.md b/README.md index 5d0a549..ef16bc5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Diff [![PkgGoDev](https://pkg.go.dev/badge/github.com/r3labs/diff)](https://pkg.go.dev/github.com/r3labs/diff) [![Go Report Card](https://goreportcard.com/badge/github.com/r3labs/diff)](https://goreportcard.com/report/github.com/r3labs/diff) [![Build Status](https://travis-ci.org/r3labs/diff.svg?branch=master)](https://travis-ci.org/r3labs/diff) +# Diff [![PkgGoDev](https://pkg.go.dev/badge/github.com/r3labs/diff)](https://pkg.go.dev/github.com/r3labs/diff) [![Go Report Card](https://goreportcard.com/badge/github.com/r3labs/diff)](https://goreportcard.com/report/github.com/r3labs/diff) [![Build Status](https://travis-ci.com/r3labs/diff.svg?branch=master)](https://travis-ci.com/r3labs/diff) A library for diffing golang structures and values. diff --git a/change_value.go b/change_value.go index 7d7ca08..4d721e9 100644 --- a/change_value.go +++ b/change_value.go @@ -123,7 +123,12 @@ func (c *ChangeValue) Set(value reflect.Value, convertCompatibleTypes bool) { } c.target.Set(value.Convert(c.target.Type())) } else { - c.target.Set(value) + if value.IsValid() { + c.target.Set(value) + } else { + t := c.target.Elem() + t.Set(reflect.Zero(t.Type())) + } } c.SetFlag(FlagApplied) }