Skip to content

Copy function does not appear to deep copy #6

Description

@dschreij

If you have the following structs:

type User struct {
    Name string
    Email string
    Company *Company
}

type Company struct {
    Name string
    Domain string
}

and do the following:

user1 := &User{
    Name: "Someone",
    Email: "someone@example.com",
    Company: &Company{
        Name: "Some co.",
        Domain: "example.com"
   },
}

var user2 User
copy.Copy(&user2, user1)

The pointer contained in user1 is copied to user2. If I now do user2.Company.Name = "Something else", the value is also changed in user1.
Is this intended? In that case, your library is not intended for use as a deep copier? It may be nice to offer the option whether to deepcopy or not as a parameter.

Thanks for all the work you put in this library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions