awalterschulze / goderive

Derives and generates mundane golang functions that you do not want to maintain yourself
Apache License 2.0
1.23k stars 44 forks source link

Create plugin for DeepCoyp for nested ptr recursion, that can copy cycles #70

Open lx-world opened 2 years ago

lx-world commented 2 years ago
type A struct {
    B *B
}

type B struct {
    A *A
}

func (a *A) Clone() *A {
    a1 := &A{B: &B{}}
    a1.B.A = a1

    tp := &A{}
    deriveDeepCopyA(tp, a1)
    return tp
}
awalterschulze commented 2 years ago

Yes good catch. Currently it is expected the deriveDeepCopy does not get looped structures, but I am open to ideas to address this and make the function more robust.

How do you propose to fix this, as in what do you propose the generated deriveDeepCopyA's code should look like?

lx-world commented 2 years ago

Yes good catch. Currently it is expected the deriveDeepCopy does not get looped structures, but I am open to ideas to address this and make the function more robust.

How do you propose to fix this, as in what do you propose the generated deriveDeepCopyA's code should look like?

I found this: https://github.com/huandu/go-clone/blob/master/clone.go ----> Slowly()

awalterschulze commented 2 years ago

Fair, yes we could made a slowly version of deepcopy. Would you be interested in contributing the new plugin?

lx-world commented 2 years ago

Fair, yes we could made a slowly version of deepcopy. Would you be interested in contributing the new plugin?

Let me try