jinzhu / copier

Copier for golang, copy value from struct to struct and more
MIT License
5.58k stars 490 forks source link

Check that we can set field value #5

Closed corpix closed 8 years ago

corpix commented 9 years ago

This PR fixes an error with unexported struct fields:

--- FAIL: TestCopyStruct (0.00s)
panic: reflect: reflect.Value.Set using value obtained using unexported field [recovered]
        panic: reflect: reflect.Value.Set using value obtained using unexported field

goroutine 5 [running]:
testing.func·006()
        /usr/lib/go/src/testing/testing.go:441 +0x181
reflect.flag.mustBeAssignable(0xf7)
        /usr/lib/go/src/reflect/value.go:219 +0x155
reflect.Value.Set(0x50eec0, 0xc208010130, 0xf7, 0x50eec0, 0xc208038220, 0xf7)
        /usr/lib/go/src/reflect/value.go:1292 +0x28
github.com/corpix/copier.Copy(0x547440, 0xc2080100e0, 0x547500, 0xc2080381e0, 0x0, 0x0)
        /home/vagrant/code/go/src/github.com/corpix/copier/copier.go:72 +0x833
github.com/corpix/copier.TestCopyStruct(0xc208062000)
        /home/vagrant/code/go/src/github.com/corpix/copier/copier_test.go:41 +0x19b
testing.tRunner(0xc208062000, 0x640da0)
        /usr/lib/go/src/testing/testing.go:447 +0xbf
created by testing.RunTests
        /usr/lib/go/src/testing/testing.go:555 +0xa8b

goroutine 1 [chan receive]:
testing.RunTests(0x5c20b8, 0x640da0, 0x3, 0x3, 0xabd6369d9bb20b01)
        /usr/lib/go/src/testing/testing.go:556 +0xad6
testing.(*M).Run(0xc2080360a0, 0x649b20)
        /usr/lib/go/src/testing/testing.go:485 +0x6c
main.main()
        github.com/corpix/copier/_test/_testmain.go:62 +0x1d5
FAIL    github.com/corpix/copier        0.001s