From 7f1a4cf3018786ebe56001ba16bfdf2407f93db9 Mon Sep 17 00:00:00 2001 From: Nikola Kovacs Date: Thu, 24 Sep 2015 13:34:51 +0200 Subject: [PATCH] Fix panic: reflect.Value.Addr of unaddressable value --- preload.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/preload.go b/preload.go index dd85c327..4621dd91 100644 --- a/preload.go +++ b/preload.go @@ -337,15 +337,24 @@ func (scope *Scope) getColumnsAsScope(column string) *Scope { } if column.Kind() == reflect.Slice { 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 { - columns = reflect.Append(columns, column.Addr()) + if column.CanAddr() { + columns = reflect.Append(columns, column.Addr()) + } } } return scope.New(columns.Interface()) 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 }