Closed math-nao closed 2 years ago
https://play.golang.org/p/H5N5ppK3vjY
package main import "log" import "github.com/jinzhu/copier" func main() { type Sample1 struct { Foobar *[]string } type Sample2 struct { Foobar []string } from := Sample1{} to := Sample2{} err := copier.CopyWithOption(&to, from, copier.Option{ DeepCopy: true, }) log.Printf("DeepCopy enabled, err: %v", err) err = copier.Copy(&to, from) log.Printf("DeepCopy disabled, err: %v", err) log.Printf("from: %v", from) log.Printf("to: %v", to) } Output: 2009/11/10 23:00:00 DeepCopy enabled, err: copy from is invalid 2009/11/10 23:00:00 DeepCopy disabled, err: <nil> 2009/11/10 23:00:00 from: {<nil>} 2009/11/10 23:00:00 to: {[]}
An error is triggered when copying a nil slice pointer to a slice field with DeepCopy, all following fields are not copied due to previous error.
Reproducible Example
https://play.golang.org/p/H5N5ppK3vjY
Description
An error is triggered when copying a nil slice pointer to a slice field with DeepCopy, all following fields are not copied due to previous error.