make sure to deep copy the field indices

This commit is contained in:
Alex Flint 2020-01-24 14:34:56 -08:00
parent 711618869d
commit 2cc1f136b1
1 changed files with 2 additions and 1 deletions

View File

@ -159,7 +159,8 @@ func walkFields(t reflect.Type, visit func(field reflect.StructField, owner refl
func walkFieldsImpl(t reflect.Type, visit func(field reflect.StructField, owner reflect.Type) bool, path []int) { func walkFieldsImpl(t reflect.Type, visit func(field reflect.StructField, owner reflect.Type) bool, path []int) {
for i := 0; i < t.NumField(); i++ { for i := 0; i < t.NumField(); i++ {
field := t.Field(i) field := t.Field(i)
field.Index = append(path, i) field.Index = make([]int, len(path)+1)
copy(field.Index, append(path, i))
expand := visit(field, t) expand := visit(field, t)
if expand && field.Type.Kind() == reflect.Struct { if expand && field.Type.Kind() == reflect.Struct {
var subpath []int var subpath []int