Commit 6850dba0 authored by Gustavo Niemeyer's avatar Gustavo Niemeyer

reflect: Fix Copy of arrays

R=golang-dev, rsc1
CC=golang-dev
https://golang.org/cl/4438077
parent b477a79c
......@@ -565,6 +565,33 @@ func TestCopy(t *testing.T) {
}
}
func TestCopyArray(t *testing.T) {
a := [8]int{1, 2, 3, 4, 10, 9, 8, 7}
b := [11]int{11, 22, 33, 44, 1010, 99, 88, 77, 66, 55, 44}
c := b
aa := ValueOf(&a).Elem()
ab := ValueOf(&b).Elem()
Copy(ab, aa)
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
t.Errorf("(i) a[%d]=%d, b[%d]=%d", i, a[i], i, b[i])
}
}
for i := len(a); i < len(b); i++ {
if b[i] != c[i] {
if i < len(a) {
t.Errorf("(ii) a[%d]=%d, b[%d]=%d, c[%d]=%d",
i, a[i], i, b[i], i, c[i])
} else {
t.Errorf("(iii) b[%d]=%d, c[%d]=%d",
i, b[i], i, c[i])
}
} else {
t.Logf("elem %d is okay\n", i)
}
}
}
func TestBigUnnamedStruct(t *testing.T) {
b := struct{ a, b, c, d int64 }{1, 2, 3, 4}
v := ValueOf(b)
......
......@@ -1546,7 +1546,7 @@ func Copy(dst, src Value) int {
// Copy via memmove.
var da, sa unsafe.Pointer
if idst.kind == Array {
da = isrc.addr
da = idst.addr
} else {
da = unsafe.Pointer((*SliceHeader)(idst.addr).Data)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment