Fix panic: reflect.Value.Addr of unaddressable value

This commit is contained in:
Nikola Kovacs 2015-09-24 13:34:51 +02:00
parent 19aacb8fbb
commit 7f1a4cf301
1 changed files with 12 additions and 3 deletions

View File

@ -337,15 +337,24 @@ func (scope *Scope) getColumnsAsScope(column string) *Scope {
} }
if column.Kind() == reflect.Slice { if column.Kind() == reflect.Slice {
for i := 0; i < column.Len(); i++ { for i := 0; i < column.Len(); i++ {
columns = reflect.Append(columns, column.Index(i).Addr()) elem := column.Index(i)
if elem.CanAddr() {
columns = reflect.Append(columns, elem.Addr())
}
} }
} else { } else {
columns = reflect.Append(columns, column.Addr()) if column.CanAddr() {
columns = reflect.Append(columns, column.Addr())
}
} }
} }
return scope.New(columns.Interface()) return scope.New(columns.Interface())
case reflect.Struct: case reflect.Struct:
return scope.New(values.FieldByName(column).Addr().Interface()) field := values.FieldByName(column)
if !field.CanAddr() {
return nil
}
return scope.New(field.Addr().Interface())
} }
return nil return nil
} }