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

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

Open
lx-world opened this issue Oct 8, 2021 · 5 comments

Comments

@lx-world
Copy link

lx-world commented Oct 8, 2021

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
Copy link
Owner

awalterschulze commented Oct 11, 2021

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
Copy link
Author

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
Copy link
Owner

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

@awalterschulze awalterschulze changed the title ptr nested recursion Deepcopy will loop indefinitely Create plugin for DeepCoyp for nested ptr recursion, that can copy cycles Oct 12, 2021
@lx-world
Copy link
Author

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

Let me try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@awalterschulze @lx-world and others