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

fixes panic when types are different #8

Merged
merged 3 commits into from
May 31, 2016
Merged

Conversation

borystomala
Copy link
Contributor

Hi,

if you've got fields with same name but different types, Copy panics due to attempt to assign value of wrong type.

type TypeStruct1 struct {
    Field1  string
    Field2  string
}

type TypeStruct2 struct {
    Field1  int
    Field2  string
}

func main() {
    ts := &TypeStruct1 {
        Field1: "str1",
        Field2: "str2",
    }

    ts2 := &TypeStruct2 {}

    Copy(ts2, ts) // panic!
}

This PR fixes this by checking if types are assignable (eg. string => string, string => interface{}).

@resouer
Copy link

resouer commented May 19, 2016

I like this feature!

@jinzhu jinzhu merged commit e15f8e2 into jinzhu:master May 31, 2016
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

Successfully merging this pull request may close these issues.

3 participants