copier icon indicating copy to clipboard operation
copier copied to clipboard

panic when copying field with same name but different type

Open radaiming opened this issue 4 years ago • 1 comments

It's a bit similar to #17:


import (
	"log"

	"github.com/jinzhu/copier"
)

type x struct{ Name string }

type structSameName1 struct {
	A string
	B []x
}

type structSameName2 struct {
	A string
	B x
}

func main() {
	obj1 := structSameName1{A: "123", B: []x{{Name: "ee"}}}
	obj2 := &structSameName2{}
	err := copier.Copy(obj2, &obj1)
	log.Println(err)
}

Running this will lead to panic: panic: reflect: call of reflect.Value.FieldByName on slice Value

Not sure if this is a bug, but it won't panic in an old e15f8e2a. And thanks for your time on this project :)

radaiming avatar Sep 12 '19 10:09 radaiming

yep, it's an issue, could you push a pull request?

nevernet avatar Dec 05 '19 05:12 nevernet

It seems to be a duplicate (or the other one is a duplicate) of #158

uded avatar Jan 06 '23 13:01 uded