scope.IndirectValue() and nil pointer

This is (patrial) solution for bug qor/qor#161. I can still reproduce it (in creation form), but this may be a qor issue.
This commit is contained in:
Alexey Derlaft 2016-02-25 11:41:59 +03:00
parent aa45da1542
commit dbdd08112e

View File

@ -28,7 +28,11 @@ func (scope *Scope) IndirectValue() reflect.Value {
if scope.indirectValue == nil { if scope.indirectValue == nil {
value := reflect.Indirect(reflect.ValueOf(scope.Value)) value := reflect.Indirect(reflect.ValueOf(scope.Value))
if value.Kind() == reflect.Ptr { if value.Kind() == reflect.Ptr {
value = value.Elem() if !value.IsNil() {
value = reflect.Indirect(value)
} else {
value.Set(reflect.New(value.Type().Elem()))
}
} }
scope.indirectValue = &value scope.indirectValue = &value
} }