copier icon indicating copy to clipboard operation
copier copied to clipboard

Strange behaviour on sub-structures

Open matthieujoossen opened this issue 3 years ago • 0 comments

Reproducible Example

https://go.dev/play/p/eotrEMU7U2Z

Description

My initial goal is to have a duplicate function.

I'm using this function (with a recover) in my production environment with copier version 0.3.4 without problem.

When I'm trying with 0.3.5 I have some troubles.

Error 1

Firstly, is that my dpulicate function is not working anymore, but without understand why.

panic: reflect: call of reflect.Value.Type on zero Value

goroutine 1 [running]:
reflect.Value.Type({0x0, 0x0, 0xc00010e750})
	/usr/local/go-faketime/src/reflect/value.go:2262 +0x12e
github.com/jinzhu/copier.copier({0x4e6e20, 0xc0001083a0}, {0x4e7260, 0xc000106200}, {0x68, 0x9e, {0x0, 0x1, 0x5de0e0}})
	/tmp/gopath4171674566/pkg/mod/github.com/jinzhu/[email protected]/copier.go:262 +0x2626
github.com/jinzhu/copier.CopyWithOption(...)
	/tmp/gopath4171674566/pkg/mod/github.com/jinzhu/[email protected]/copier.go:76
main.duplicate({0x4e7260, 0xc000106200})
	/tmp/sandbox2567366000/prog.go:64 +0x265
main.main()
	/tmp/sandbox2567366000/prog.go:51 +0x265

Case 2

In a more classic case, copying from a structure to another one (line 46), copier.CopyWithOption is working but not well.

Indeed, elts field is not empty despite the `copier:"-"` tag.

Moreover, if I use copier.Copy instead of copier.CopyWithOption:

  • UT field is not empty
  • elts field is not empty

matthieujoossen avatar Mar 02 '22 17:03 matthieujoossen