mergo
mergo copied to clipboard
mergo WithSliceDeepCopy into differen types will causes painc
package main
import (
"testing"
"github.com/imdario/mergo"
)
func TestMerge(t *testing.T) {
dst := []interface{}{
map[string]int{
"a": 1,
},
}
src := []interface{}{
"nil",
}
err := mergo.Merge(&dst, src, mergo.WithSliceDeepCopy)
if err != nil {
t.Errorf("unexpected error %v", err)
}
}
below is painc message
=== RUN TestMerge
--- FAIL: TestMerge (0.00s)
panic: reflect: reflect.Value.Set using unaddressable value [recovered]
panic: reflect: reflect.Value.Set using unaddressable value
goroutine 18 [running]:
testing.tRunner.func1.2({0x4c90a0, 0xc00009e450})
/usr/local/go-faketime/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
/usr/local/go-faketime/src/testing/testing.go:1399 +0x39f
panic({0x4c90a0, 0xc00009e450})
/usr/local/go-faketime/src/runtime/panic.go:884 +0x212
reflect.flag.mustBeAssignableSlow(0x0?)
/usr/local/go-faketime/src/reflect/value.go:260 +0x85
reflect.flag.mustBeAssignable(...)
/usr/local/go-faketime/src/reflect/value.go:247
reflect.Value.Set({0x4cc9c0?, 0xc0000a02d0?, 0x0?}, {0x4c90a0?, 0x50a108?, 0x0?})
/usr/local/go-faketime/src/reflect/value.go:2154 +0x6a
github.com/imdario/mergo.deepMerge({0x4cc9c0?, 0xc0000a02d0?, 0xcc000b287f8?}, {0x4c90a0?, 0x50a108?, 0x0?}, 0x0?, 0x1, 0xc0000b2020)
/tmp/gopath3385435001/pkg/mod/github.com/imdario/[email protected]/merge.go:114 +0x537
github.com/imdario/mergo.deepMerge({0x4c74e0?, 0xc0000a8078?, 0x197?}, {0x4c74e0?, 0xc0000a8090?, 0x97?}, 0xc00009be30?, 0x0, 0xc0000b2020)
/tmp/gopath3385435001/pkg/mod/github.com/imdario/[email protected]/merge.go:230 +0x1525
github.com/imdario/mergo.merge({0x4c4de0, 0xc0000a8078}, {0x4c74e0, 0xc0000a8090}, {0xc00003c740, 0x1, 0x4b5225?})
/tmp/gopath3385435001/pkg/mod/github.com/imdario/[email protected]/merge.go:366 +0x32b
github.com/imdario/mergo.Merge(...)
/tmp/gopath3385435001/pkg/mod/github.com/imdario/[email protected]/merge.go:296
main.TestMerge(0xc000082820)
/tmp/sandbox1600088922/prog.go:19 +0x126
testing.tRunner(0xc000082820, 0x4eb5a8)
/usr/local/go-faketime/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
/usr/local/go-faketime/src/testing/testing.go:1493 +0x35f
Program exited.