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

mergo WithSliceDeepCopy into differen types will causes painc #220

Closed
zhiyu0729 opened this issue Aug 17, 2022 · 0 comments · Fixed by #221
Closed

mergo WithSliceDeepCopy into differen types will causes painc #220

zhiyu0729 opened this issue Aug 17, 2022 · 0 comments · Fixed by #221

Comments

@zhiyu0729
Copy link
Contributor

playground

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/mergo@v0.3.13/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/mergo@v0.3.13/merge.go:230 +0x1525
github.com/imdario/mergo.merge({0x4c4de0, 0xc0000a8078}, {0x4c74e0, 0xc0000a8090}, {0xc00003c740, 0x1, 0x4b5225?})
	/tmp/gopath3385435001/pkg/mod/github.com/imdario/mergo@v0.3.13/merge.go:366 +0x32b
github.com/imdario/mergo.Merge(...)
	/tmp/gopath3385435001/pkg/mod/github.com/imdario/mergo@v0.3.13/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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants