Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic when copying field with same name but different type #43

Closed
radaiming opened this issue Sep 12, 2019 · 2 comments
Closed

panic when copying field with same name but different type #43

radaiming opened this issue Sep 12, 2019 · 2 comments

Comments

@radaiming
Copy link

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 e15f8e2. And thanks for your time on this project :)

@nevernet
Copy link

nevernet commented Dec 5, 2019

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

@uded
Copy link
Collaborator

uded commented Jan 6, 2023

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

@uded uded closed this as completed Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants